Runit

Runit is an init program and an alternative to systemd. There are also other alternatives to systemd such as OpenRC in gentoo and s6. Of course, we could also use the old SysV scripts, but they're a bit old. Runit has some advantages. First, it's super fast booting up; in only a few seconds booting up you already arrive at the login prompt. Secondly, it's quite easy to write service files for Runit. They are simple sh scripts that execute the program.

How to install Runit on debian

On Debian, the runit installation can be a bit tricky. If we try to simply install runit-init, it won't let us.

If we are in the process of installing Debian from the installation iso, then we can get a chroot into the target, and it's a bit easier to install runit. But if the Debian system is already installed, and want to switch instead, then we need the help of the runit-systemd helper package.

First, we have to remove the 'init' package (it's actually a metapackage)

sudo dpkg -r init

And now we can install runit:

sudo apt install runit runit-init getty-run runit-services libsystemd0-

If we are not using a chroot (eg the Debian system is already installed), we first have to install the helper package: sudo apt install runit-systemd and later sudo reboot And after installing the helper package we can install the desired Runit packages and remove systemd.

Now we reboot the machine to enter into runit, and now we can install our runit programs.

sudo apt install runit runit-init runit-helper getty-run runit-services libsystemd0- systemd- systemd-sysv- libsystemd0- libsystemd-shared- util-linux apt

Unfortunately, the version of Runit that comes in the Debian repositories has some issues. Instead of using runit-version scripts, it instead uses SysV scripts to preserver compatibility, and as such it's a bit slow.

So, instead we will use some runit scripts from cloux on github:

git clone https://github.com/cloux/runit-base.git

In this repository, it contains it's own versions of 1,2,3 (which are the scripts that run at boot-time and while shutting down)

First we copy those scripts:

sudo cp -r runit-base/etc/runit/* /etc/runit/

Let's see what do the scripts contain:

The important bits in the first script (/etc/runit/1) is the following:

for f in /etc/runit/bootup/*.sh; do
	[ -r "$f" ] && . "$f"
done

In other words, it runs all the scripts in /etc/runit/bootup when booting the machine up

If we look in that directory, we see that they contain numbers at the front. This decides which order they will run in. All those that end in '.sh' will be executed when the machine boots up.

I like to have the /tmp directory mounted on RAM, so i'll tweak the configuration of 04-tmpfs.sh and replace the line RAMTMP=no to RAMTMP=yes

Also, i don't need to replace the commands to '.sysv', so i can deactivate a script in /etc/runit/autorun: chmod -x /etc/runit/autorun/runit-init

The advantage of this repo is that it contains runit-style scripts for many services. Let's look in the folder where we cloned the repository. In the folder ~/runit-base/etc/sv we find many scripts. If we want to install a package which has a runit service, we can simply copy that directory into /etc/sv

For example, if we install chrony

sudo apt install chrony

If chrony doesn't come with a runit configuration in /etc/sv, we can copy the directory: sudo cp -r runit-base/etc/sv/chrony /etc/sv

In the new directory, there are some unneeded files (because runit will create them automatically):

rm -r /etc/sv/chrony/supervise; rm -r /etc/sv/chrony/.meta; rm -r /etc/sv/chrony/log/supervise

Now, to activate the chrony daemon, it's very simple. We simply have to symbolically link the directory from /etc/sv to /etc/service.

ln -s /etc/sv/chrony /etc/service/

We also want to install socklog sudo apt install socklog --no-install-recommends

sudo cp -r runit-base/etc/sv/socklogd /etc/sv/; sudo ln -s /etc/sv/socklogd /etc/service/

In runit, to stop and restart services it's very similar to systemd. sv start/stop service

But to deactivate or activate services (so that they start automatically) it's a bit different. It's necessary to link /etc/sv/daemon to /etc/service.