termux-boot icon indicating copy to clipboard operation
termux-boot copied to clipboard

Boot scripts not being automatically executed after boot

Open ivanfor opened this issue 5 years ago • 17 comments

** Edited after further testing **

Problem description Scripts in ~/.termux/boot seem not being executed at boot ... Is there anything i can do to troubleshoot?

Steps to reproduce

  1. Install termux app (from f-droid in my case)
  2. install termux-boot app (from f-droid as well)
  3. Start termux boot app (see the instructions)
  4. Create ~/.termux/boot dir
  5. Create the following script:
$ cat 00_autostart 
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
date > $HOME/date

Expected behavior Create/update the $HOME/date file after boot

Additional information

  • Termux application version: 0.95. Termux boot is version 0.7
  • Android OS version: 9.0
  • Device model: unbranded chinese tablet.

ivanfor avatar Jul 24 '20 19:07 ivanfor

I am having this issue as well. I am trying to autostart an instance of node red. It seems to be acquiring the wake-lock properly, but then says 0 sessions. I would love to see a resolution to this.

Cjkeenan avatar Sep 02 '20 21:09 Cjkeenan

@Cjkeenan for node-red you need to fix the shebang of the node-red script.

It will not start an actual terminal session though, termux-boot expects the command to finish (or continue in the background)

Grimler91 avatar Sep 03 '20 04:09 Grimler91

interesting, is there a guide somewhere on how to fix this? I was just following the guide on Node-RED's own documentation for how to install on Android and they recommended autostarting via termux:boot

Cjkeenan avatar Sep 03 '20 04:09 Cjkeenan

@Cjkeenan after installing node-red you see that the first line (the shebang) of the node-red script is #!/usr/bin/env node (check with head $(which node-red). /usr/bin/env does not exist on android though, so the shebang should be changed to #!/data/data/com.termux/files/usr/bin/env node.

When you run node-red in a normal session you are saved by the LD_PRELOAD'ed library termux-exec, which automatically translates /usr/bin -> /data/data/com.termux/files/usr/bin.

An alternative fix would be to not rely on the shebang at all in the termux-boot script, instead of having something like

#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
node-red

You can do

#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
node ~/node_modules/.bin/node-red # change path if you installed globally

The prefixed node then overrides the shebang in the node-red script.

Grimler91 avatar Sep 03 '20 07:09 Grimler91

Sweet that seems to have fixed it. I just copied the path from which node-red and then put that path into the argument for the node command, see the whole script below.


#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
node /data/data/com.termux/files/user/bin/node-red

Are there any issues with what I have done?

Cjkeenan avatar Sep 03 '20 07:09 Cjkeenan

/data/data/com.termux/files/user/bin/node-red should be /data/data/com.termux/files/usr/bin/node-red

It should not have any other side-effects

Grimler91 avatar Sep 03 '20 07:09 Grimler91

yeah that was a typo on my part, it was actually usr in the script. Thank you for your help.

Cjkeenan avatar Sep 03 '20 08:09 Cjkeenan

Not sure if this issue is still alive but...

I am running Android 10 on a Teclast M40. I have followed all the instructions and advice from this thread and from the original documentation. I won't bother with the details at this time... but termux:boot is simply not starting. I.e., all installed from f-droid, ran termux:boot (though there is no indication it does anything, other that show the instructions... Is this expected?), script is in ~/.termux/boot, executable permissions, etc...

Reboot... there is no output from logcat, or in the log file (created from my script with "set -x; exec > ~/boot.log 2>&1". The script runs and creates the log when executed manually from termux shell.

Has anyone gotten this to work on Android 10? If so, can you please advise...

Many thanks!

tunerooster avatar Jan 20 '21 16:01 tunerooster

I have the same problem with termux:boot doesn't have a session so that I can't ssh to termux. And I found that use "am start -n com.termux/.HomeActivity" can open termux so there would have a session (if you don't unlock your phone, the notification would still be 0 session but there seems to have a session because I can ssh to termux in this situation. ). You can add it into your start scripts in ~/.termux/boot/ . As for running other commands, I use "screen -dm" and it worked. I founded that there exist the screens I created in ~/.termux/boot/start.sh.

Has anyone gotten this to work on Android 10? If so, can you please advise...

I think this is a general problem happening to any Android version because I meet it on Android 7.1.

Pardon my bad English.

MCorTHATMC avatar Mar 13 '21 05:03 MCorTHATMC

Has anyone gotten this to work on Android 10? If so, can you please advise...

I think this is a general problem happening to any Android version because I meet it on Android 7.1.

I'm using Android 12 non-rooted and Termux boot works fine. You must do the scripts inside Termux and not device root of user storage which is easily lost understanding. The scripts will otherwise not be found. It should work on all devices. It just needs the script at the hard coded Termux app only path.

(Clarification: rooted user can use but shouldn't; this is a app itself use only location path; users shouldn't touch it; app can touch it because its its own private storage location; so do it in Termux app to do it.)

It could be that specific devices are blocking boot receiver or some other odd thing. You have to narrow that down. But if you do logcat verbose and filter to "termux" and wait, then termux boot should at least show up if the device is allowing the app to start on boot. If it starts on boot then it should have a message about no scripts or some other further info to go on.

Xavron avatar May 15 '22 13:05 Xavron

I have similar issues on my Android 7 phone with Termux-boot-Addon.

First of all: If sshd is started via ~/.termux/boot/start.sh, it takes at least about 2 minutes more after device power on than starting sshd via ~/.bashrc (and Termux-App via "Launch on Boot" https://f-droid.org/de/packages/news.androidtv.launchonboot/). But I need to disable SIM PIN entering at device start for this way (otherwise .bashrc will not be executed before tapping on the notification).


If starting with Termux-Boot-Addon this one works:

#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
sshd

This one not:

#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
. $PREFIX/etc/profile
sv start sshd ## ??? not sure if needed

=> no sshd running (but notification shown with Termux Wakelock) (so first line of script was executed but not more). ("sv start sshd" works if entered in a shell) source: https://wiki.termux.com/wiki/Termux:Boot

uwe-007 avatar Aug 30 '22 14:08 uwe-007

One more curious (on Android 10): This one works (sshd running):

#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
date > /data/data/com.termux/files/home/boot.log
sleep 2
sshd -p 2222


This one not (only pkill added):

#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
date > /data/data/com.termux/files/home/boot.log
pkill sshd
sleep 2
sshd -p 2222

uwe-007 avatar Aug 31 '22 16:08 uwe-007

@uwe-007 if you have enabled sshd at some point (sv-enable sshd) then there should be no need to run sv up sshd, and this should work:

$ cat .termux/boot/start-services
#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
source /data/data/com.termux/files/usr/etc/profile.d/start-services.sh

(The wiki needs to be updated)

Grimler91 avatar Aug 31 '22 17:08 Grimler91

@Grimler91 Thanks, Henrik, I will give it a try. And why can't I use pkill (second post)?

uwe-007 avatar Sep 01 '22 07:09 uwe-007

@uwe-007 not sure, adb logcat from a computer when phone is connected and usb debugging enabled should show logs with error message

Grimler91 avatar Sep 01 '22 08:09 Grimler91