In this post, I will show you how to create and manage services in Termux.
1
2
Termux is an Android terminal emulator and Linux environment app
that works directly with no rooting or setup required.
Termux uses runit
as its init system.
1
2
“runit is a cross-platform Unix init scheme with service supervision,
a replacement for sysvinit, and other init schemes.”
1
pkg install termux-services
Then restart Termux so that the service-daemon is started.
Now let’s create a service,
I am going create a service for gogs (a git service).
All termux services are located at $PREFIX/var/service
($PREFIX=$HOME/../usr
).
Create a folder for the service and name it as the application name. In my case that is gogs
.
1
mkdir $PREFIX/var/service/gogs
Then create a symbolic link with termux-logger.
1
2
3
mkdir $PREFIX/var/service/gogs/log
ln -sf $PREFIX/share/termux-services/svlogger $PREFIX/service/gogs/log/run
Now write the service file for the application with the below content,
1
touch $PREFIX/var/service/gogs/run
1
2
3
# Gogs service for termux
#!/data/data/com.termux/files/usr/bin/sh
exec gogs web 2>&1
You can get help to write runit service here.
make it executable,
1
chmod +x $PREFIX/var/service/gogs/run
Now restart Termux and run,
1
sv up gogs
It will work smoothly.
Here are some useful commands about termux services,
To enable service to start at boot,
1
sv-enable <service>
To disable from starting at boot,
1
sv-disable <service>
To start a service,
1
sv up <service>
To stop a service,
1
sv down <service>
Bonus Topic: Manage proot(s) in Termux
You can install multiple Linux based distributions using proot-distro ,
Lists supported distributions and their installation status,
1
proot-distro list
To install a distribution,
1
proot-distro install <distro name>
To login into a distribution,
1
proot-distro login <distro name>
Delete a distribution from Termux,
1
proot-distro remove <distro name>
To reinstall a specified distribution,
1
proot-distro reset <distro name>
To backup a distribution,
1
proot-distro backup <distro name>
To restore a distribution from backup,
1
proot-distro restore <distro name>
This post also published on Medium.