| Version 3 (modified by jrollins, 5 years ago) (diff) |
|---|
Replacing init with runit on Debian GNU/Linux
This is based mostly on the notes on replacing init with runit written by the runit developers.
Install the needed Debian runit packages:
# aptitude install runit runit-services runit-run
The runit-run program is the one that actually replaces /sbin/init with /sbin/runit-init:
proton:~ 0# ls -al /sbin/init* lrwxrwxrwx 1 root root 10 2007-12-21 18:40 /sbin/init -> runit-init -rwxr-xr-x 1 root root 32652 2007-01-30 17:27 /sbin/init.sysv proton:~ 0#
runit-init is what will now start on boot and handle starting services. It also emulates many of the commands that could be passed to init. The configuration directory for runit-init is /etc/runit:
proton:~ 0# ls -al /etc/runit/ total 10 drwxr-xr-x 3 root root 1024 2007-12-21 18:41 . drwxr-xr-x 51 root root 4096 2007-12-21 18:41 .. -rwxr-xr-x 1 root root 188 2006-11-04 14:33 1 -rwxr-xr-x 1 root root 576 2006-11-04 14:33 2 -rwxr-xr-x 1 root root 239 2006-11-04 14:33 3 -rwxr-xr-x 1 root root 209 2006-11-04 14:33 ctrlaltdel drwxr-xr-x 4 root root 1024 2007-12-21 18:40 runsvdir proton:~ 0# ls -al /etc/runit/runsvdir/ total 4 drwxr-xr-x 4 root root 1024 2007-12-21 18:40 . drwxr-xr-x 3 root root 1024 2007-12-21 18:41 .. lrwxrwxrwx 1 root root 7 2007-12-21 18:40 current -> default drwxr-xr-x 2 root root 1024 2007-12-21 18:41 default drwxr-xr-x 2 root root 1024 2007-12-21 18:40 single proton:~ 0#
The main service directory is /var/service (which is a link to /etc/runit/runsvdir/current, which is a link to either /etc/runit/runsvdir/default or /etc/runit/runsvdir/single, for default or single user mode, i think):
proton:~ 0# ls -al /var/service/ total 2 drwxr-xr-x 2 root root 1024 2007-12-21 18:41 . drwxr-xr-x 4 root root 1024 2007-12-21 18:40 .. lrwxrwxrwx 1 root root 15 2007-12-21 18:40 getty-1 -> /etc/sv/getty-1 lrwxrwxrwx 1 root root 15 2007-12-21 18:40 getty-2 -> /etc/sv/getty-2 lrwxrwxrwx 1 root root 15 2007-12-21 18:40 getty-3 -> /etc/sv/getty-3 lrwxrwxrwx 1 root root 15 2007-12-21 18:40 getty-4 -> /etc/sv/getty-4 lrwxrwxrwx 1 root root 15 2007-12-21 18:40 getty-5 -> /etc/sv/getty-5 lrwxrwxrwx 1 root root 20 2007-12-21 18:41 socklog-klog -> /etc/sv/socklog-klog lrwxrwxrwx 1 root root 20 2007-12-21 18:41 socklog-unix -> /etc/sv/socklog-unix proton:~ 0#
These service directories start the gettys, and the main system log daemons. The next thing to do make service directories for the rest of the services that we want handled by runit. This is where runit-services comes in. runit-services provides service directories for a bunch of standard services, all located in /etc/sv:
proton:~ 0# ls /etc/sv/ apache dhcp getty-2 nfs-kernel-server socklog-inet socklog-unix chrony exim getty-3 portmap socklog-klog squid cron gdm getty-4 postfix socklog-notify ssh dhclient getty-1 getty-5 README socklog-ucspi-tcp xdm proton:~ 0#
/etc/sv/README gives a good intro on how to get these services started. I'm going to start by getting the cron service working:
proton:~ 0# /etc/init.d/cron stop Stopping periodic command scheduler: crond. proton:~ 0# dpkg-divert --add /etc/init.d/cron Adding `local diversion of /etc/init.d/cron to /etc/init.d/cron.distrib' proton:~ 0# mv /etc/init.d/cron /etc/init.d/cron.distrib proton:~ 0# ln -s /usr/bin/sv /etc/init.d/cron proton:~ 0# ln -s /etc/sv/cron /var/service/ proton:~ 0# sv status cron run: cron: (pid 2033) 2s proton:~ 0#
That was simple. Now ssh:
proton:~ 0# /etc/init.d/ssh stop Stopping OpenBSD Secure Shell server: sshd. proton:~ 0# dpkg-divert --add /etc/init.d/ssh Adding `local diversion of /etc/init.d/ssh to /etc/init.d/ssh.distrib' proton:~ 0# mv /etc/init.d/ssh /etc/init.d/ssh.distrib proton:~ 0# ln -s /usr/bin/sv /etc/init.d/ssh proton:~ 0# ln -s /etc/sv/ssh/ log/ run supervise proton:~ 0# ln -s /etc/sv/ssh /var/service proton:~ 0# sv status ssh run: ssh: (pid 2059) 2s; run: log: (pid 2057) 2s proton:~ 0#
An important one to me, which does not have an included service dir, is a serial console. So I went ahead and wrote one:
proton:~ 0# ls -al /etc/sv/getty-S0/ total 4 drwxr-xr-x 2 root root 1024 2007-12-21 19:32 . drwxr-xr-x 26 root root 1024 2007-12-21 19:26 .. -rwxr-xr-x 1 root root 32 2007-12-21 19:27 finish -rwxr-xr-x 1 root root 43 2007-12-21 19:30 run lrwxrwxrwx 1 root root 20 2007-12-21 19:32 supervise -> /var/run/sv.getty-S0 proton:~ 0# cat /etc/sv/getty-S0/run #!/bin/sh exec getty -L ttyS0 115200 vt102 proton:~ 0# cat /etc/sv/getty-S0/finish #!/bin/sh exec utmpset -w ttyS0 proton:~ 0#
Finally, reboot your system:
/sbin/init.sysv 6

