termux / termux-boot

Termux add-on app allowing programs to be run at boot.
https://f-droid.org/en/packages/com.termux.boot
931 stars 219 forks source link

Can not start script with sudo #63

Open myfreax opened 3 years ago

myfreax commented 3 years ago

Problem description startup script not execute when Andorid restart

Steps to reproduce

  1. Install termux boot app
  2. create startup script in /data/data/com.termux/files/home/.termux/boot
  3. In my ubuntu terminal enter adb shell then check nginx process by ps | grep nginx. Have no any output netease-proxy.sh
    #!/data/data/com.termux/files/usr/bin/sh
    termux-wake-lock
    sshd
    nohup /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/home/apps/netease/proxy/app.js -p 5621:5620 -f 59.111.181.60 > /dev/null  2>&1 &
    sudo nginx

    The script can not execute When Andorid system started. I try manual start termux-boot-app, startup script executed and start app.js and sshd. But sudo nginx not start. When try executed script ./netease-proxy.sh in termux terminal it work well nginx.conf

user root; worker_processes 1;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;
    server {
        listen 80;
    server_name music.163.com interface.music.163.com;
        location / {
                proxy_pass http://127.0.0.1:5621;
                proxy_set_header HOST 'music.163.com';
        }
}
server {
    listen 443;
    server_name music.163.com interface.music.163.com;
    location / {
            proxy_pass https://127.0.0.1:5620;
            proxy_set_header HOST 'music.163.com';
        }
}

}

**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
Nginx,App.js,sshd  will start when Android started
**Additional information**
termux-info

Packages CPU architecture: aarch64 Subscribed repositories:

sources.list

deb https://grimler.se/termux-packages-24/ stable main

game-repo (sources.list.d/game.list)

deb https://dl.bintray.com/grimler/game-packages-24 games stable

science-repo (sources.list.d/science.list)

deb https://dl.bintray.com/grimler/science-packages-24 science stable Updatable packages: apt/stable 2.2.2 aarch64 [upgradable from: 2.1.18] ca-certificates/stable,stable 20210413-2 all [upgradable from: 20210125] curl/stable 7.76.1 aarch64 [upgradable from: 7.75.0-1] dialog/stable 1.3-20210324-0 aarch64 [upgradable from: 1.3-20200327-0] game-repo/stable,stable 1.3 all [upgradable from: 1.2] inetutils/stable 1.9.4-11 aarch64 [upgradable from: 1.9.4-10] libcurl/stable 7.76.1 aarch64 [upgradable from: 7.75.0-1] libgcrypt/stable 1.9.1 aarch64 [upgradable from: 1.8.7] libnettle/stable 3.7.2 aarch64 [upgradable from: 3.7] nano/stable 5.6.1 aarch64 [upgradable from: 5.5] ncurses/stable 6.2.20200725-2 aarch64 [upgradable from: 6.2.20200725-1] openssl/stable 1.1.1k-2 aarch64 [upgradable from: 1.1.1i] psmisc/stable 23.4 aarch64 [upgradable from: 23.3-2] science-repo/stable,stable 1.2 all [upgradable from: 1.1] tar/stable 1.34 aarch64 [upgradable from: 1.32-6] termux-exec/stable 1:0.9 aarch64 [upgradable from: 1:0.8] termux-tools/stable,stable 0.118 all [upgradable from: 0.104] Android version: 7.1.2 Kernel build information: Linux localhost 3.10.84-perf-gc8921aa #1 SMP PREEMPT Sat Dec 1 00:17:25 CST 2018 aarch64 Android Device manufacturer: nubia Device model: NX569J

Xdand commented 3 years ago

Manda comado bom

Sugarpie69 commented 2 years ago

Help

KodeToad commented 2 years ago

I experienced a similar issue with calling any scripts I'd written from inside the boot script, but calling any builtin command or pkg application was fine. What I ended up doing as a workaround was to embed all the script code inside the boot script. Nothing else I tried seemed to work including nohup sh and & The script permissions were set to 0700. The commands I called successfully from inside the script are

It's probably worth noting that it was on a Motorola G6 and judging from other issues like this these are platform specific problems. On the G6 I had to disable battery optimisation but there is no specific permission for startup. I used com.termux_118.apk and com.termux.boot_7 packages from FDroid

Are there any other suggestion as to what might cause this kind of behaviour?

Grimler91 commented 2 years ago

Are there any other suggestion as to what might cause this kind of behaviour?

Assuming you are not running with sudo then issues could be caused my invalid shebangs. For termux-boot shebang needs to be valid, so for example #!/data/data/com.termux/usr/bin/bash instead of #!/usr/bin/bash

AlaisterLeung commented 2 years ago

This works for me:

#!/data/data/com.termux/files/usr/bin/sh
sudo -u root /system/bin/sh -c "your_command_here"