Git Product home page Git Product logo

termux-services's Introduction

How to run services with runit on Termux

  1. Install termux-services with pkg install termux-services
  2. Restart your shell so that the service-daemon is started
  3. Enable a service by running sv-enable <service>, or just start it with sv up <service>
  4. Check the log content of $PREFIX/var/log/sv/<service>/current in case there are problems

You can also stop services with sv down <service>, or disable them with sv-disable <service> A service is disabled if $PREFIX/var/service/<service>/down exists, so the sv-enable and sv-disable scripts touches, or removes, this file.

termux-services's People

Contributors

birros avatar grimler91 avatar neo-oli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

termux-services's Issues

service command instead of sv

OpenWRT, TurrisOS, Ubuntu has a service command.
I used it so many times. But I was wondered why termux-services uses sv command.
This difference adds some confusion for me.
Is it possible to add an alias/symlink service to sv.
Then it will be easier to write documentation: the commands will be the same for all systems

unable to open supervise/ok: file does not exist

I keep getting this when I try to enable ftp

~  sv-enable ftpd
warning: ftpd: unable to open supervise/ok: file does not exist
 ✘  ~  sv up ftpd
warning: ftpd: unable to open supervise/ok: file does not exist
 ✘  ~ 

Some termux-info

Android version:
9
Kernel build information:
Linux localhost 4.9.117+ #1 SMP PREEMPT Fri Apr 19 13:20:06 CST 2019 armv8l Android
Device manufacturer:
HUAWEI
Device model:
AMN-LX9

add sv-status

sv-status sshd would tell me if sshd is enabled and is running

sshd stops working after a period of time

I'm already using sv-enable sshd to keep ssh running in the background. This works fine for a couple of hours but will fail after a longer period of time. I've checked files in $PREFIX/var/log/sv/sshd and it seems ok. Here are some lines:

2022-11-20_16:46:23.79949 Server listening on :: port 8022.
2022-11-20_16:46:23.80024 Server listening on 0.0.0.0 port 8022.
2022-11-20_16:46:29.39072 Accepted password for root from 10.23.7.31 port 1179 ssh2
2022-11-20_16:46:48.98431 Accepted password for root from 10.23.7.31 port 1182 ssh2
2022-11-20_16:57:41.23194 session_signal_req: session signalling requires privilege separation
2022-11-20_16:57:41.24203 session_signal_req: session signalling requires privilege separation
2022-11-20_16:57:41.24307 session_signal_req: session signalling requires privilege separation
2022-11-20_16:57:41.24348 Received disconnect from 10.23.7.31 port 1179:11: 
2022-11-20_16:57:41.24432 Disconnected from user root 10.23.7.31 port 1179
2022-11-20_18:36:58.51402 Accepted password for root from 10.23.7.31 port 2164 ssh2
2022-11-20_18:37:42.77302 session_signal_req: session signalling requires privilege separation
2022-11-20_18:37:42.77391 session_signal_req: session signalling requires privilege separation
2022-11-20_18:37:42.77435 session_signal_req: session signalling requires privilege separation
2022-11-20_18:37:42.77460 Received disconnect from 10.23.7.31 port 2164:11: 
2022-11-20_18:37:42.77529 Disconnected from user root 10.23.7.31 port 2164
2022-11-20_22:02:10.41650 Accepted password for root from 10.23.7.31 port 20722 ssh2
2022-11-20_22:02:16.79189 session_signal_req: session signalling requires privilege separation
2022-11-20_22:02:16.79238 session_signal_req: session signalling requires privilege separation
2022-11-20_22:02:16.79259 session_signal_req: session signalling requires privilege separation
2022-11-20_22:02:16.79277 Received disconnect from 10.23.7.31 port 20722:11: 
2022-11-20_22:02:16.79354 Disconnected from user root 10.23.7.31 port 20722
2022-11-21_00:44:20.35834 Accepted password for root from 10.23.7.31 port 12540 ssh2
2022-11-21_00:44:28.10984 session_signal_req: session signalling requires privilege separation
2022-11-21_00:44:28.11039 session_signal_req: session signalling requires privilege separation
2022-11-21_00:44:28.11061 session_signal_req: session signalling requires privilege separation
2022-11-21_00:44:28.11118 Received disconnect from 10.23.7.31 port 12540:11: 
2022-11-21_00:44:28.11193 Disconnected from user root 10.23.7.31 port 12540

But when I woke up the next day, ssh had stopped working. It's been like this for days, and once I opened a new session sshd came back. I checked sv status sshd when I knew it stopped working and it gave back runsv not running.
Anywhere I can see the logs of runit?
Some termux-info

Termux Variables:
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main stable main
Updatable packages:
libmpfr/stable 4.1.1-1 aarch64 [upgradable from: 4.1.0-1]
termux-tools version:
1.31.1
Android version:
8.1.0
Kernel build information:
Linux localhost 4.9.82-perf+ #2 SMP PREEMPT Fri Sep 24 18:34:23 CST 2021 aarch64 Android

Extra: I've disabled doze mode on Android and I have two other network related processes remain safe in ubuntu provided by proot-distro.

forking?

my run file looks like this:

#!/data/data/com.termux/files/usr/bin/sh
exec proot-distro login archlinux --user docmax --shared-tmp --bind /storage/emulated/0:/mnt/sdcard -- sh -c 'DISPLAY=:0 exec dbus-launch xfce4-session'

when i try to stop with "sv down vncserver" the service is still running. i think it's because sv is not aware of the processes anymore. can this be fixed?

anyway to list all jobs?

is there any way to list all jobs and their status since ps only show two process without root?
image

runsv not running

On lineageos17.1

After install and restart and command

sv-enable tor

I get:

fail: tor: runsv not running

Can't start any service

No matter what I try to start - whether openssh, or transmission - I get this error (transmission example).

fail: transmission: unable to change to service directory: file does not exist.

Android 13, unrooted, zsh , termux v 0.118. I restarted shell after installation termux-services, even restarted the phone and reinstalled transmission after - the same error.

sshd stops working overnight

I'm unable to ssh into a device running Termux and the sshd service after it has been running overnight. Some details:

  1. Device is left charging overnight with termux-wake-lock on
  2. It's not a networking issue because ssh -p8022 localhost normally works but in the morning it results in ssh: connect to host localhost port 8022: Connection refused
  3. $PREFIX/var/log exists but $PREFIX/var/log/sv/ does not, so I can't check the current log file
  4. stopping the service via sv down sshd then manually starting sshd using the sshd command allows the connection, so it's likely an issue with the service?
  5. restarting the service via sv down sshd and sv up sshd also results in connection refused
  6. restarting the service via sv exit sshd and sv up sshd allows the connection
  7. sv status sshd reports the following before restarting the service:
    run: sshd: (pid 3537) 83017s, normally down; down: log: 0s, normally up, want up
  8. sv status sshd reports the following after restarting the service:
    run: sshd: (pid 1433) 111s, normally down; down: log: 1s, normally up, want up

Hopefully this is enough information. If more is needed I'll need to wait until the next day before I can run more commands :)

Unable to get the sshd service up

Hello,

I've followed the installation/setup guide from both the Wiki and the README from this repository, but I'm getting this error whenever I try to run/enable the sshd service:

$ sv up sshd
warning: sshd: can't open supervise/ok: No such file or directory

And yes, I did a complete restart of Termux after I installed termux-services. Not sure if this is relevant or not, but I'm not using bash as my default shell, I'm using fish.

There's no sv directory in my $PREFIX/var/log/ as well:

$ ls -la $PREFIX/var/log/
total 32
drwx------ 3 u0_a139 u0_a139 4096 Dec 29 11:49 .
drwx------ 9 u0_a139 u0_a139 4096 Dec 29 13:47 ..
-rw-r--r-- 1 u0_a139 u0_a139  853 Jan  1 10:03 alternatives.log
drwx------ 2 u0_a139 u0_a139 4096 Jan  3 10:34 apt

Can you guys help?
Thanks!

unable to change to service directory

When I am running

sv-enable mosquitto

It's giving me this error

fail: mosquitto: unable to change to service directory: file does not exist

Can you please help ?
Thanks for this library

Локализация

Добрый день. Планируете добавить Русскую локализацию?

Cannot access service directory

I am getting the "unable to change to service directory" error even though the directory and files exist:

~ $ ls $PREFIX/var/service/mysqld
down  log  run
~ $ sv up mysqld
fail: mysqld: unable to change to service directory: file does not exist

All services can't be stopped or disabled

sv-disable did create the down files, but runit/runsv doesn't know anything about or care about any down files, completely ignores them, and runs all services anyways. Services can't even be stopped or set to down. I had to rm -rf all service dirs that I wanted to disable, and kill -9 all runsv instances (1 per service). kill didn't seem to work most of the time (usually no effect, if any effect, sometimes defunct/zombie, rarely ended process), but kill -9 did end them clean.

I had sshd, mysqld, postgres, and cupsd dirs installed by default (by something else, not my intent), but did not want to run them, only maybe if-and-as-needed (rarely or never), otherwise leave it disabled. I just wanted to play with cronie a bit, and explore various features, vs Termux:Boot. But then the most basic features -- sv down/stop, sv-disable, don't even work...

unable to open supervise/ok

On android 9 and 10.

After install and restart and command

sv-enable tor

I get:

warning: tor: unable to open supervise/ok: file does not exist

Support for OkcAgent

OkcAgent runs a daemon and set $SSH_AUTH_SOCK to use openkeychain.

command to up service

$PREFIX/bin/okc-ssh-agent $PREFIX/var/run/okc-ssh-agent.sock > /dev/null 2>&1 & echo $! > $PREFIX/var/run/okc-ssh-agent.pid
export SSH_AUTH_SOCK=$PREFIX/var/run/okc-ssh-agent.sock

command to down service

kill -9 $(cat $PREFIX/var/run/okc-ssh-agent.pid)

command to status service

if [ -f /proc/$(cat $PREFIX/var/run/okc-ssh-agent.pid)/exe ]; then
   echo 'okc-ssh-agent is running...'
else
  echo 'okc-ssh-agent is not running...'
fi

more info
https://github.com/DDoSolitary/OkcAgent
DDoSolitary/OkcAgent#18

[BUG] "sv stop sshd" does not kill sshd process

problem reproduction

$ ps -ef  | grep sshd
u0_a565   2396  2395  0  1970 ?        00:00:04 runsv sshd
u0_a565  11266  2396  0  1970 ?        00:00:00 sshd -D -f /data/data/com.termux/files/home/etc/ssh/sshd_config -e
u0_a565  11294 11266  0  1970 ?        00:00:00 /data/data/com.termux/files/usr/bin/sshd -D -f /data/data/com.termux/files/home/etc/ssh/sshd_config -e -R

$ cat service/sshd/supervise/pid
11266

# log pid is empty
$ cat cat service/sshd/log/supervise/pid

$ sv stop sshd
ok: down: sshd: 1s

# `sv stop sshd` only kill pid 11266. The pid 11294 is still running.
$ ps -ef  | grep sshd
u0_a565   2396  2395  0  1970 ?        00:00:04 runsv sshd
u0_a565  11294     1  0  1970 ?        00:00:00 /data/data/com.termux/files/usr/bin/sshd -D -f /data/data/com.termux/files/home/etc/ssh/sshd_config -e -R

What I expected

Kill both pid 11266 and 11294.

sshd service config

$ cat service/sshd/run
#!/data/data/com.termux/files/usr/bin/sh
exec sshd -D -f /data/data/com.termux/files/home/etc/ssh/sshd_config -e 2>&1

# down script is empty
$ cat service/sshd/down

sv_enable not found

~ $ termux-info
Application version:
0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.org/apt/termux-main/ stable main
Updatable packages:
All packages up to date
Android version:
11
Kernel build information:
Linux localhost 4.9.290-perf-g3d062cf9c496 #1 SMP PREEMPT Thu Dec 9 05:57:04 UTC 2021 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
MI 8

tried stop/restart runsv. No result

~ $ pstree
?─┬─?─┬─com.termux───14*[{com.termux}]
  │   └─com.termux.boot───13*[{com.termux.boot}]
  ├─httpd───5*[httpd]
  ├─runsvdir───3*[runsv]
  └─sshd───sshd───bash───pstree

Service in background for a bash script

I need to run a shell script written in bash, basically it with a timer in infinite loop, has to check some data with php .
So the script needs to be run in background.
I followed the guide as said, I run sv up myservice but nothing happens.
What the workaround to exec a simple bash as service ?
A simple guide to make a service containing a bash script ?
I tried another way using daemonize and it works, but I want to follow a better way ...
Thanks you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.