termux / termux-boot

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

Processes are duplicating #9

Closed darkoverlordofdata closed 5 years ago

darkoverlordofdata commented 6 years ago

I'm getting duplicate processes popping up.

My boot starts a php server for codiad ide:

~/.termux/boot/boot.sh:

!/data/data/com.termux/files/usr/bin/env bash

/data/data/com.termux/files/home/codiad-run.sh > /dev/null 2>&1 & disown

It runs this simple php server loop:

~/.codiad-run.sh:

!/data/data/com.termux/files/usr/bin/env bash

cd /data/data/com.termux/files/home/codiad while true ; do php -S 127.0.0.1:8080 -t /data/data/com.termux/files/home/codiad ; pkill php; done > /dev/null

The boot script is the only place where I'm invoking codiad-run.sh. Everything runs ok for several minutes after booting, until Codiad dies, and when I check, there are 4 processes runing codiad-run.sh.

I've tried starting it with nohup instread of disown, and I also tried leaving the console connected, but same result.

I'm not sure if this is related; when I start apache2 instead, I see it is also getting duplicated, with multiple copies of /data/data/com.termux/files/usr/bin/httpd -k start running. Apache still works, I don't know if it's expecting this behavior or not.

darkoverlordofdata commented 6 years ago

I tried adding crond to my boot script, and ended up with multiple cron jobs running. The longer I left it running, the more jobs. When I finally rebooted (it was the only way I could find to stop the proliferation) there were 5 cron jobs running.

travislee89 commented 6 years ago

I encountered the same issue. Every time I login via ssh, it would start an AndroidRuntime and tried to start [/data/data/com.termux/files/home/.termux/boot/sshd]

02-01 20:05:18.392  2850  4142 I termux-task: [4140] starting: [/data/data/com.termux/files/home/.termux/boot/sshd]
02-01 20:05:19.530  4153  4153 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 10081 <<<<<<
02-01 20:05:19.537  4153  4153 D AndroidRuntime: CheckJNI is OFF
02-01 20:05:19.606  4153  4153 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
02-01 20:05:19.687  4153  4153 I Radio-JNI: register_android_hardware_Radio DONE
02-01 20:05:19.720  4153  4153 D AndroidRuntime: Calling main entry com.android.commands.am.Am
02-01 20:05:19.726  4153  4153 D AndroidRuntime: Shutting down VM

So I wrote a script to determine the service is running. This is the example:

if ! pgrep "sshd" >/dev/null; then echo "[Starting sshd...]" && sshd && echo "[sshd started...]"; else echo "[sshd is running]"; fi
if ! pgrep "frpc" >/dev/null; then echo "[Starting frpc...]" && (nohup frpc &) && echo "[frpc started...]"; else echo "[frpc is running...]"; fi
macerg commented 6 years ago

I am also getting multiple instances of crond running. Is anyone looking for a fix to this?

pacien commented 6 years ago

I proposed a fix for this issue (pull request #12).

markosjal commented 6 years ago

I am running a script that launches a python2 command from termux boot . The python script should write a file then quit (as I understand it).

I think my issue is similar. Instead of writing the file once then quitting, it re writes the file every 10 minutes. I can see this by the file time.

I do not mind that it is running every 10 Minutes but would much prefer it to run once per hour.

I downloaded the latest version on f-droid only 2 days ago , so no fix yet, and I really need this badly.

markosjal commented 6 years ago

as a work-around is it possible to change the job reschedule interval?

I have no idea how to apply this patch!

I took weeks to come up with a solution on android and this was the only thing that really worked without requiring me to have super powers. Unfortunately without new APKs, from a user point of view, the bug remains.

Any hope for finding new apk in the near future on f-droid? I am at the final phase of this project and now stuck on this bug! HELP!

mentalisttraceur commented 6 years ago

Just out of curiosity, does this problem go away if you run your services in the more modern service-supervision style, as opposed to in the daemonize-into-background style?

To use sshd as an example, I am currently testing the following script for running that service at boot:

termux-wake-lock
exec sshd -D

sshd -D is the service-supervision way, where the process remains in the foreground and directly parented to the caller (the exec just avoids leaving the shell process as a middleman).

I'll report back if I notice this or other issues cropping up in this setup.

function1983 commented 5 years ago

Thanks to @travislee8964 suggestion. This works out pretty well for me. No more duplicating tasks.

Content of ~/.termux/boot/start-at-boot

#!/data/data/com.termux/files/usr/bin/bash
if ! pgrep "sshd" >/dev/null; then echo "[Starting sshd...]" && sshd && echo "[ssh started...]"; else echo "[ssh is running]"; fi
if ! pgrep "crond" >/dev/null; then echo "[Starting crond...]" && crond && echo "[crond started...]"; else echo "[crond is running]"; fi
if ! pgrep "python3" >/dev/null; then { nohup python3 your_python_file.py & } 1>stdout.txt 2>stderr.txt ; else echo "[python is running]"; fi

Cron gives you more control though. Content of crontab -e:

*/10 * * * * /data/data/com.termux/files/home/run_once_very_ten_mins.sh

and ~/run_once_very_ten_mins.sh

#!/bin/bash
if ! pgrep "python3" >/dev/null; then { nohup python3 your_python_file.py & } 1>stdout.txt 2>stderr.txt ; else echo "[python is running]"; fi

Best.

kaefert commented 5 years ago

this is a symptom of the issue https://github.com/termux/termux-boot/issues/20

roman-rybalko commented 5 years ago

Here is a workaround.

fornwall commented 5 years ago

Sorry for the long delay here! An updated version 0.6 of Termux:Boot has been released which should fix this issue - please let me know if the problem remains in that version!