Skip to content

Repository files navigation

runit-services

runit service definitions for Void Linux, in one small POSIX-sh style. Each service runs with no config; ./conf is an optional override. glibc and musl.

Style

Every run (and finish) follows the same shape — read one and you know them all:

#!/bin/sh
exec 2>&1
[ -r ./conf ] && . ./conf
: "${USER:=root}"
: "${OPTS=default}"
exec chpst -u "$USER:$(id -Gn "$USER" | tr ' ' :)" daemon $OPTS
  • POSIX /bin/sh. exec 2>&1 so output goes to the supervisor. exec the real process so it owns the PID and signals; never pipe.
  • $OPTS/$ARGS are unquoted (they must word-split); everything else is quoted.
  • Privilege drop via chpst -u "user:groups" with the full group list; root-only services skip it.

Config

Defaults live in run/finish as : "${VAR:=default}" — the scripts are their own documentation. Override by creating ./conf (sourced first, so it wins):

# <service>/conf
USER="_daemon"
OPTS="--verbose"

conf is gitignored, so overrides never dirty the repo. Executables are called by name via runit's inherited PATH; set PATH in conf for unusual locations. HOME (where used) resolves from the service user's passwd entry, overridable in conf.

A service that can't run until something exists logs one line and sleeps instead of crash-looping (config/image missing → 60s).

Install

git clone <repo-url> /etc/runit-services
ln -s /etc/runit-services/<service> /etc/sv/<service>   # available
$EDITOR /etc/sv/<service>/conf                          # optional
ln -s /etc/sv/<service> /var/service/                   # enable

sv up|down|status|restart <service>; disable with rm /var/service/<service>.

Templates

runsvdir and openvpn read their instance name from the symlink and derive their target — no editing, one definition serves many:

# per-user services -> supervises ~<user>/runsvdir/service
ln -s /etc/runit-services/runsvdir /etc/sv/runsvdir-<user>

# openvpn: plain -> /etc/openvpn/openvpn.conf
#          suffixed -> /etc/openvpn/<name>/openvpn.conf (cwd = that dir)
ln -s /etc/runit-services/openvpn /etc/sv/openvpn-<name>

Then ln -s /etc/sv/<instance> /var/service/. Instances and the plain service coexist. runsvdir is Linux-only (reads /proc). Per-user services source: https://docs.voidlinux.org/config/services/user-services.html

Every other service is a copy, not a template: symlinking one dir under two names would share a single conf, so multiple instances would collide. To run more than one (e.g. two podman-service containers), copy the directory and give each its own conf:

cp -r /etc/runit-services/podman-service /etc/sv/podman-nginx
$EDITOR /etc/sv/podman-nginx/conf
ln -s /etc/sv/podman-nginx /var/service/

Prefer running podman-service/podman-compose rootless under a user's runsvdir for better isolation than root.

Logging

Services write to stdout. To persist, add a log service:

mkdir -p /etc/sv/<service>/log /var/log/<service>
printf '#!/bin/sh\nexec svlogd -tt /var/log/<service>\n' > /etc/sv/<service>/log/run
chmod +x /etc/sv/<service>/log/run

About

collection of runit init scripts

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages