Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not executing script at boot #5

Open
Keith-S-Thompson opened this issue Aug 7, 2017 · 37 comments
Open

Not executing script at boot #5

Keith-S-Thompson opened this issue Aug 7, 2017 · 37 comments
Labels

Comments

@Keith-S-Thompson
Copy link

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.

@fornwall
Copy link
Member

fornwall commented Aug 7, 2017

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 fornwall added the bug label Aug 7, 2017
@Keith-S-Thompson
Copy link
Author

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
Copy link
Author

Same problem with a Nexus 9 running Android 7.1.1.

@Keith-S-Thompson
Copy link
Author

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

@fornwall
Copy link
Member

fornwall commented Aug 8, 2017

@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?

@Keith-S-Thompson
Copy link
Author

Keith-S-Thompson commented Aug 11, 2017

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.

@Unrud
Copy link

Unrud commented Sep 3, 2017

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

@rclai
Copy link

rclai commented Nov 13, 2017

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?

@fornwall
Copy link
Member

@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?

@scytale
Copy link

scytale commented Nov 18, 2017

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

@walkertraylor
Copy link

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.

@leo-b
Copy link

leo-b commented Dec 22, 2017

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.

@wxc1
Copy link

wxc1 commented Dec 24, 2017

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

@macerg
Copy link

macerg commented Feb 15, 2018

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
Copy link

macerg commented Feb 18, 2018

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
Copy link

macerg commented Feb 18, 2018

crond now not starting either.

@macerg
Copy link

macerg commented Feb 23, 2018

Anyone alive?

@rclai
Copy link

rclai commented Mar 12, 2018

💀

@cs8425
Copy link

cs8425 commented Apr 4, 2018

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.

@macerg
Copy link

macerg commented Apr 5, 2018

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

@macerg
Copy link

macerg commented Apr 5, 2018

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.

@DarrenRainey
Copy link

DarrenRainey commented Apr 21, 2018

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
Copy link

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

@Justsoos
Copy link

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.

@pointbre
Copy link

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

@StevenSalazarM
Copy link

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/

@liubo-chongqing
Copy link

根本没有启动

@frank7d
Copy link

frank7d commented Jan 27, 2019

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

@MCTyler
Copy link

MCTyler commented Jan 30, 2019

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.....

@vias79
Copy link

vias79 commented Jun 20, 2019

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

@uudruid74
Copy link

None of this works for me. No idea whats going on

@buzhibujuelb
Copy link

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.....

That works on my old phone(Samsung J7008). Thank you!

@CieNTi
Copy link

CieNTi commented Jun 22, 2020

@uudruid74 I'm running Stock Android 9 and not a single thing worked 100% for me.

I read somewhere about "DuraSpeed", and that is my case. Once I included termux and friends in this list (and everything this post suggest), I finally got my termux working for, now, 4h (my max was 20 minutes) ... let's see tomorrow.

Maybe it is your case?

@tunerooster
Copy link

What DuraSpeed list? Can you detail how you got it working? ...still does not work for me. Thanks!

@uudruid74 I'm running Stock Android 9 and not a single thing worked 100% for me.

I read somewhere about "DuraSpeed", and that is my case. Once I included termux and friends in this list (and everything this post suggest), I finally got my termux working for, now, 4h (my max was 20 minutes) ... let's see tomorrow.

Maybe it is your case?

@Keith-S-Thompson
Copy link
Author

My current $HOME/.termux/boot/start script does some logging that may shed some light on ... something.

It logs the output of the uptime command when it executes. On my phone (Moto G Power 2021, Android 11), the uptime by the time the command runs varies from about 2 minutes to 10 minutes.

It's possible that I've sometimes thought that the startup script didn't run at all, when in fact it just hadn't run yet. As far as I can tell, it's now at least reasonably reliable.

@Xavron
Copy link

Xavron commented Jul 10, 2022

Clarified: I came here because of DHA:empty #25 which doesn't mean anything as-is but was just found mentioned only here.

If its not executing on boot then you have something wrong with your configuration (or yes not waiting long enough but logcat will show you which). If its executing then being killed and looking like its not starting (when viewed from user perspective Android UI) then the following is true.

I have my own developed app for myself with start on boot and it stays running on the same device without the need of any of similar stuff above.

A test I just did on an affected Samsung with what @buzhibujuelb wrote, only termux-wake-lock was needed to fix it. Yet, that shouldn't be necessary either. Start on boot works fine without wake locks.

Its probably possible that the app can be changed to fix it but I don't have time to look at what its doing and why its being destroyed simply because of a wake lock.

Seems more like a bug to me in that viewpoint. Wake lock shouldn't be necessary.

Further clarification if its not apparent: the app runs fine without a wake lock except at boot and its killed fast enough for the notification to never show up.

@termux termux deleted a comment from CdJody Aug 14, 2022
@termux termux deleted a comment from 0-Rainer-Stoff-0 Dec 23, 2022
@termux termux deleted a comment from YVS37 Feb 17, 2023
@kidroca
Copy link

kidroca commented Oct 14, 2023

This is what worked for me on an Android 7.0 device:

~ $ cat .termux/boot/1
#!/bin/sh

OUT=/data/data/com.termux/files/home/boot-test.txt

termux-wake-lock
echo "$(date +%c): Boot script starting" >> $OUT
HOMEDIR=~/
echo "Home: $HOMEDIR" >> $OUT

echo "Starting service daemon" >> $OUT

export SVDIR=$PREFIX/var/service
export LOGDIR=$PREFIX/var/log
service-daemon start >>$OUT 2>&1

I have a few services like dropbear (ssh server) and crond and I couldn't connect over ssh after reboot unless I first manually open the Termux App

It was only after updating my post boot script like so, that I was able to ssh into the device after reboot without any physical interactions with the actual device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests