Services init and supervision with Runit

about

runit is a init scheme with service supervision .

project web page @

runit in the context of system start up

    boot
      |
    kernel
    loads
      |
 init scheme starts 

related workflows

manage processes

manage packages

install runit

We may not have to install runit. Usually when installing devuan (!workflow link!) we choose our init system.

$ sudo apt-get install runit

offline help

$ cd /usr/share/doc/runit/*

deb package of runit contains man pages and html help files.

runit deb package

devuan pkginfo/runit @ , debian tracker @ ,

binaries

runsvdir

After linux boots at some point it starts runit which will start runsvdir. What does runsvdir do ? According to man pages:

runsvdir starts a runsv(8) process for each subdirectory, or symlink to a directory, in the services directory dir,and restarts a runsv(8) process if it terminates.At least every five seconds runsvdir checks whether the time of last modification, the inode, or the device, of the services directory dir has changed.If so, it re-scans the service directory, and if it sees a new subdirectory, or new symlink to a directory, in dir, it starts a new runsv(8) process.

If runit is running we see in the process tree that runsvdir is running: runsvdir -P /etc/service log So it monitors /etc/service directory and for each directory in /etc/service it starts runsv passing as argument that /etc/service/foo directory as argument. There must be a run script to start a certain service.

locations

  • /etc/sv - contains service directories for a collection of runit compatible services.
    • packages that are compatible with runit contains /etc/sv/programname/* files . Most needed is the run file
    • $ apt-file -x search '/etc/sv.*$'
  • /etc/service - that is the directory monitored by runsvdir. So links to /etc/sv files must be created here in order for runit and runsvdir to see a service and control it.The /etc/service directory contains a series of soft links representing the processes currently managed by runit. So /etc/sv contains service's control inteface scripts, /etc/service contains the actively managed services.
  • /etc/runit/runsvdir

managing running services

find runit compatible services in Devuan

pre: pkg/apt-file installed and updated.

$ apt-file -x search '/etc/sv.*$'

check runit state

$ cat /proc/1/comm

If runit is running in our system will could see it in our process tree on the top.

$ pstree
runit─┬─dhclient
      ├─runsvdir─┬─runsv───apache2───2*[apache2───26*[{apache2}]]
      │          ├─7*[runsv───getty]
      │          ├─runsv
      │          ├─runsv─┬─dbus-daemon
      │          │       └─svlogd
      │          ├─runsv─┬─dhclient
      │          │       └─svlogd
      │          ├─runsv─┬─sshd───sshd───sshd───bash───tmux: client
      │          │       └─svlogd
      │          ├─runsv───cron
      │          ├─runsv───elogind
      │          ├─runsv───rsyslogd───3*[{rsyslogd}]
      │          ├─runsv─┬─exim4
      │          │       └─svlogd
      │          └─runsv───sleep

We see running : runit , runsvdir , runsv

how runit works

That diagram's creator is unknown .

                                       kernel
                                           |
                                          1|
      .--- /etc/runit/reboot ---.        init        14
  ,---|            2            |<--- runit-init <---- init 0|6
  |   -- /etc/runit/stopit --          |
  |                                 13     |
  '------------------------------------>  3|
                                 .-----> runit
                                 |         |
                                 |         |
			.---<---------<----+-------->---------.
			|        |         |                  |
                       4|        |        6|                10|
                    runit/1      |      runit/2           runit/3
			|        |         |                  |
                       5|        |        7|                11|
                   start things  |     runsvdir              sv
			|        |         |                  |
			|        |        8|                  |
			-->--|       runsv         /var/service/*
                                 |         |                  |
                                 |         |                12|
                                 |   .../current/*       stop things
                                 |         |                  |
                                 |         |                  |
                                 |    start things            |
                                 |   monitor things           |
                                 |   restart things           |
                                 |         |                  |
                                 |        9|                  |
                                 ---<-----------<---------'

issues

In devuan/daedalus searching for packages with /etc/sv we dont see such dirs for apache or cron or dhclient. How are they created ?