Open ivanfor opened 4 years ago
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 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)
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 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.
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?
/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
yeah that was a typo on my part, it was actually usr in the script. Thank you for your help.
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!
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.
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.
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
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 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 Thanks, Henrik, I will give it a try. And why can't I use pkill (second post)?
@uwe-007 not sure, adb logcat
from a computer when phone is connected and usb debugging enabled should show logs with error message
so, its the weirdest thing....it worked perfectly yesterday and i rebooted numerous times to test it. today, my script is not being executed. i tried various shebangs...yesterday it actually worked without any. i'm calling an adb command. if i execute my shell script manually from termux, it works fine.
whats going on?
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