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

Not executing script at boot

Open Keith-S-Thompson opened this issue 7 years ago • 37 comments

There's a good chance I've missed something obvious, but Termux:Boot isn't working for me.

I've installed Termux:Boot on my Nexus 6 running Android 7.0, and I've launched the app.

$ ls -l ~/.termux/boot/
total 4
-rwxr-xr-x 1 u0_a98 u0_a98 141 Aug  6 20:51 start
$ cat ~/.termux/boot/start
#!/data/data/com.termux/files/usr/bin/sh

crond
sshd
echo "$(date +'%a %F %T %Z') /data/data/com.termux/files/home/boot/start" >> $HOME/.log
$

(The documentation doesn't say the script needs to be executable or have a #! line, but I figured it wouldn't hurt.)

The script doesn't execute when I reboot the phone. sshd isn't running, and nothing is written to $HOME/.log.

Keith-S-Thompson avatar Aug 07 '17 04:08 Keith-S-Thompson

Just to check - you've launched the Termux:Boot app once, right?

After rebooting the device, can you check if the command logcat -s termux:* outputs anything interesting?

fornwall avatar Aug 07 '17 20:08 fornwall

Yes, I did launch Term:Boot. (More than once, actually; I presume that's not a problem.)

logcat -s termux:* just prints --------- beginning of main and hangs.

Keith-S-Thompson avatar Aug 07 '17 21:08 Keith-S-Thompson

Same problem with a Nexus 9 running Android 7.1.1.

Keith-S-Thompson avatar Aug 07 '17 23:08 Keith-S-Thompson

I've modified my boot scripts, and I'm seeing different behavior. I previously said that $HOME/.log wasn't being updated. I can't confirm that.

I'm testing using a Nexus 6 running Android 7.0, a Nexus 7 (2nd edition) running Android 6.0.1, and a Nexus 9 running Android 7.1.1. At the moment, I seem to be getting consistent behavior on all three.

I've attached the four startup files I currently have in $HOME/.termux/boot. All four of them execute after reboot, writing to the corresponding $HOME/start?.out files. The out files indicate that everything ran correctly, showing PIDs for the sshd and crond processes. But afterwards, the sshd and crond processes are not running. Output on the Nexus 9:

$ head start?.out
==> start0.out <==
Mon Aug  7 18:08:17 PDT 2017
 18:08:17 up 2 min,  0 users,  load average: 10.84, 3.62, 1.29

==> start1.out <==
Mon Aug  7 18:08:17 PDT 2017
 18:08:17 up 2 min,  0 users,  load average: 10.84, 3.62, 1.29
Start crond
Start sshd
Done

==> start2.out <==
Mon Aug  7 18:08:17 PDT 2017
 18:08:17 up 2 min,  0 users,  load average: 10.84, 3.62, 1.29

==> start3.out <==
crond: 4666
sshd:  4671
$

Still nothing from logcat is termux:*

start.zip

Keith-S-Thompson avatar Aug 08 '17 01:08 Keith-S-Thompson

@Keith-S-Thompson Hm, you can try running termux-wake-lock as first statement in a startup script, which would lessen the risk of the processes being killed of by the system. Does that help in keeping the processes alive?

fornwall avatar Aug 08 '17 11:08 fornwall

That seems to have done the trick.

I was avoiding using termux-wake-lock because I didn't want to consume too much battery, but I see the display still blanks after a bit. Is there some documentation on just what termux-wake-lock does? (Wait, I see that a Google search for "Android wake lock" gets some good results; I'll read up on it.)

Thanks.

Keith-S-Thompson avatar Aug 11 '17 02:08 Keith-S-Thompson

The problem is that the boot script exits. termux-wake-lock works for sshd but it didn't work with all daemons that I tried to run.

My solution is to keep the script running by not daemonizing:

sshd -D

Or something like:

sshd
cat

Unrud avatar Sep 03 '17 14:09 Unrud

I'm on an LG V30.

This is what happened after I restarted my phone:

$ adb logcat -s termux:*
--------- beginning of system
--------- beginning of main
11-12 19:33:08.495 10219 10219 I termux  : Executed files at boot: 001-start-sshd, 002-start-test-server

My 001-start-sshd has the same code as your README for startingsshd.

And my 002 script just starts a "hello world" Node.js HTTP server.

I could not ssh into the phone after restarting, and the Node.js server didn't run.

I'd like to lock in the $1.99, but it's not working for me. How can I help to troubleshoot this?

rclai avatar Nov 13 '17 00:11 rclai

@rclai Can you test if using running sshd -D as proposed by @Unrud works, perhaps in combination with termux-wake-lock to keep the processes alive?

fornwall avatar Nov 15 '17 00:11 fornwall

Oh! the sheer effort to type 4 chars at boot... :-)

Issue replicated on Android 7.1.1 on Chromebook x86-64

$ logcat -s termux:* --------- beginning of main 11-17 22:10:38.459 1032 1032 I termux : Executed files at boot: start_tmux --------- beginning of system

$ cat ~/.termux/boot/start_tmux termux-wake-lock tmux

scytale avatar Nov 18 '17 06:11 scytale

I am having the same issue on a Samsung A5, running a sshd start script as well as another. I can run the scripts using Termux:Widget or manually just fine.

walkertraylor avatar Nov 25 '17 15:11 walkertraylor

It looks like the forked daemon processes get killed asyncronously a few seconds after the start script exited:

12-22 14:00:23.072  3802  3874 I libprocessgroup: Killing pid 12181 in uid 10294 as part of process group 11964

Even if I start a new session and a new process group using setsid sshd..., the processes get killed after the fork at the first login:

12-22 14:15:11.155  3805  4767 I ActivityManager: Killing 11364:com.termux/u0a294 (adj 906): DHA:empty #33
12-22 14:15:11.155  3805  3901 I libprocessgroup: Killing pid 11521 in uid 10294 as part of process group 11364
12-22 14:15:11.155  3805  3901 I libprocessgroup: Killing pid 13113 in uid 10294 as part of process group 11364
12-22 14:15:11.155  3805  3901 I libprocessgroup: Killing pid 13116 in uid 10294 as part of process group 11364
12-22 14:15:11.155  3805  3901 I libprocessgroup: Killing pid 13117 in uid 10294 as part of process group 11364

It looks like the problem is that the process-group is considered as empty and thus is a candidate to get killed: https://stackoverflow.com/questions/33335246/process-being-killed-on-marshmallow-but-not-on-lollipop

Starting the same script with Tasker and the Termux::Task plugin triggered by a Device Boot event works fine though.

Btw.: I had to additionally whitelist Termux from Android's standard doze mode on my Samsung Galaxy S7.

leo-b avatar Dec 22 '17 13:12 leo-b

Not working for me either on asus zenfone 2

bash-4.4$ logcat --------- beginning of main 12-24 11:02:33.550 3421 3421 W System : ClassLoader referenced unknown path: /data/app/com.termux.boot-2/lib/x86 12-24 11:02:33.560 3421 3421 V Monotype: SetAppTypeFace- try to flip, app = co m.termux.boot 12-24 11:02:33.560 3421 3421 V Monotype: Typeface getFontPathFlipFont - sy stemFont = default#default 12-24 11:02:43.130 4135 4135 V Monotype: SetAppTypeFace- try to flip, app = co m.termux 12-24 11:02:43.140 4135 4135 V Monotype: Typeface getFontPathFlipFont - sy stemFont = default#default 12-24 11:02:43.150 4135 4135 V Monotype: SetAppTypeFace- try to flip, app = co m.termux 12-24 11:02:43.150 4135 4135 V Monotype: Typeface getFontPathFlipFont - sy stemFont = default#default 12-24 11:02:43.200 4135 4149 E WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found

wxc1 avatar Dec 24 '17 16:12 wxc1

I'm having the same issue on a Doogee T5 Android 6. wake-lock starts most boots, crond starts most boots, sshd never starts.

macerg avatar Feb 15 '18 02:02 macerg

sshd still not running at startup. autossh running OK (for a reverse tunnel) but as ssh not starting, no connection. Help would be appreciated. Updatable packages: All packages up to date System information: Linux localhost 3.18.19+ #1 SMP PREEMPT Sat Dec 10 21:57:17 CST 2016 aarch64 Android Termux-packages arch: aarch64 Android version: 6.0 Device manufacturer: DOOGEE Device model: T5

macerg avatar Feb 18 '18 01:02 macerg

crond now not starting either.

macerg avatar Feb 18 '18 03:02 macerg

Anyone alive?

macerg avatar Feb 23 '18 03:02 macerg

💀

rclai avatar Mar 12 '18 16:03 rclai

Hi, I have same issue too. I'm using ZenFone 2 Laser (ZE550KL) with android 6.0 (already change zenfone built-in permission). I would like to start sshd and some simple server written in golang. After some trial and error, I found the solution.

First and most important, if there have more than one file, all file won't execute (at least in my test, see PR #11 ). MUST start ALL program in ONE FILE!

Second, screen -dmS $name $your_cmd won't work in my test.

Third, sshd & and nohup sh -c "$your_cmd" seems work fine. (I did not test & with other services) nohup + su works too, nohup su app_91 -c "$your_cmd", but need change app_91 to yours.

After all, I end up with nohup sh -c "$cmd" method.

cs8425 avatar Apr 04 '18 21:04 cs8425

Thanks cs8425, Worked a treat! More patience than me!

macerg avatar Apr 05 '18 08:04 macerg

Must admit, I'd have thought that the developers would have been all over this! They have shown no interest whatsoever! Won't be doing any more donations.

macerg avatar Apr 05 '18 15:04 macerg

I'm also having problems trying to get this to run at boot I've tried everything including the sshd example with termux-wake-lock but it seems to just hang on the beginning main part.

also I installed both apps from FDroid

DarrenRainey avatar Apr 21 '18 17:04 DarrenRainey

while I have been unable to get the app to work I currently have a work around which is to write my commands in the ~/.bashrc file so the commands run whenever the app is started with root it is possible to just have a init script start the app at boot or without root there maybe another app to start termux at boot and run these commands

DarrenRainey avatar Apr 24 '18 12:04 DarrenRainey

my miui9 android6, works after adding the termux:boot to Autostart permission. and as @DarrenRainey says, I add the start script to .bashrc too, termux:boot just takes effect at boot once.

Justsoos avatar May 28 '18 12:05 Justsoos

nohup sh -c 'syncthing' works for syncthing on samsung galaxy s6 with android 7.0. Thank you guys!

pointbre avatar Jun 10 '18 22:06 pointbre

idk if it can help someone but just saying i had the same problem testing in a zenfone phone, googled it and found out that zenfone blocks some apps to start when the phone boot, to allow termux to execute the scripts you need to give it permission to be executed at boot: https://www.asus.com/support/FAQ/1013752/

StevenSalazarM avatar Jul 07 '18 07:07 StevenSalazarM

根本没有启动

liubo-chongqing avatar Jul 19 '18 16:07 liubo-chongqing

I'm on LineageOS 15.1, Oreo, XiaoMi MI5s Same problem. termux.boot got killed after a couple of seconds. No sshd. -Setup/Battery/Optimization -Show ALL apps -Select Termux.boot in order to NOT optimize the app.

  • Reboot Now termux.boot survives and sshd is running, Frank

frank7d avatar Jan 27 '19 19:01 frank7d

You guys looking for this?

    termux-wake-lock
    sshd
    cd ~/
    screen -wipe
    sleep 10
    screen -d -m termux-chroot ./xteverun -port="8080"

I also have it starting a script called xTeVe in a "detached" screen, but you get the general idea.....

MCTyler avatar Jan 30 '19 01:01 MCTyler

I'm on LineageOS 15.1, Oreo, XiaoMi MI5s Same problem. termux.boot got killed after a couple of seconds. No sshd. -Setup/Battery/Optimization -Show ALL apps -Select Termux.boot in order to NOT optimize the app.

  • Reboot Now termux.boot survives and sshd is running, Frank

This is the answer that works.

I'm on a Samsung S8. Go into the Apps->Termux:Boot->Inactivate Optimizations

vias79 avatar Jun 20 '19 08:06 vias79