runit is a alternative to init: it runs daemons on a system. It provides a simpler interface for logging and "supervision": it will restart services if they die. It is also much easier to use it to set up a custom daemon for yourself: no messing with init scripts and things like that.

How to install the service

Install the runit package, and the runit daemon (runsvdir) will automatically start (from the normal sysv init system), and run everything in /etc/service. Then, just link your own services from there (ln /path/to/you/directory/ /etc/service/). The runit supervisor service should automatically start.

How to set up a service directory

First, make a run script and chmod a+x it. This script should run whatever daemon you want, WITHOUT backgrounding it, and log to standard output. You can include whatever shell script constructs you would like (including loops which loop to "daemonize" it) Example:

exec 2>&1
exec sudo dnsmasq -d -C dnsmasq.conf

You can also make a SVDIR/finish which is run each time SVDIR/run exits. You can touch the file SVDIR/supervise/down to make the service not automatically start. The chpst program (included with runit) is designed to be a wrapper to do things like change the user and group the

To make regular users able to control the service, chmod the SVDIR/supervise directory to be writeable by the users who need to control it.

Logging

Make a SVDIR/log/ directory. Make a SVDIR/log/run script (and chmod a+x it). The standard output of the run and finish scripts are piped into this script, and this script is responsible for writing it to the proper files.

The following mini-script will use the svlogd program (included with runit) to log to the SVDIR/log/ directory as user richard and with a timestamp. svlogd has many options to configure timestampings, ignores, and configs/processings.

exec chpst -urichard svlogd -tt ./

If logs seem to not be appearing, make sure the run script is outputting on stdout instead of stderr.

DebianNotes/Runit (last edited 2011-01-17 16:07:59 by RichardDarst)