runit openrc gentoo

I decided to have another go at runit, this time on my gentoo.

I had been thinking about this, since I noticed this on Gentoo Wiki OpenRC
It does not function as a replacement for the /sbin/init

I keep wanting to trim everything down, and have been integrating busybox to replace userspace utilities. The gentoo wiki says:
Busybox can be used to replace most of the userspace utilities needed by OpenRC (init, shell, awk and other POSIX tools), by using a complete Busybox as shell for OpenRC all the calls that normally would cause a fork/exec would be spared, improving the overall speed. This process is not yet streamlined.
Please note that there are currently many Busybox applets that are incompatible with OpenRC.

It was that last bit which concerned me, and I didn't want to risk hacking it too much.

But I could hack /bin/init provided by sys-apps/sysvinit. I do like runit, and decided to install sys-process/runit which provides /sbin/runit-init.

The install was pretty simple:
# emerge --ask sys-process/runit

I was very surprised when my regular clean up routine asked to unmerge sys-apps/sysvinit.

# emerge --depclean --ask 
... 
... 
>>> Calculating removal order... 

>>> These are the packages that would be unmerged: 

 sys-apps/sysvinit 
    selected: 2.88-r9 
   protected: none 
     omitted: none 

All selected packages: =sys-apps/sysvinit-2.88-r9 

>>> 'Selected' packages are slated for removal. 
>>> 'Protected' and 'omitted' packages will not be removed. 

Would you like to unmerge these packages? [Yes/No] n

Was it not needed anymore?

Wanting to see what gentoo does out of the box, I rebooted, and appended init=/sbin/runit-init to the kernel cmdline boot prompt.

My system booted up cleanly, and I could login and startx.

However, I had no network. But I could manually start my network, and all was fine.

# /etc/init.d/net.wlp3s0 start

Subsequently, I realised that many other services had not started... narrowed them all to the default runlevel.

Apparently, all the services in opnerc runlevels sysinit & boot had started, but those in runlevel default had not.

So this was the only thing to do, in order to have runit instead of sysvinit on gentoo out of the box. Impressive!

I had a look at runit's runlevel 1.

$ cat /etc/runit/1                                                                                                                                                                                   
#!/bin/sh
# system one time tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

RUNLEVEL=S /sbin/rc sysinit
RUNLEVEL=S /sbin/rc boot

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

It looks like runit runlevel 1 is triggering the openrc runlevels sysinit and boot, but default is not listed there. So I just added it in there.

$ cat /etc/runit/1                                                                                                                                                                                   
#!/bin/sh
# system one time tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

RUNLEVEL=S /sbin/rc sysinit
RUNLEVEL=S /sbin/rc boot
RUNLEVEL=S /sbin/rc default

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

I rebooted again to test.. all services working, and no errors or warnings.

I decided to go for broke, and remove sysvinit with a bit of trepidation, but knowing that I could put it back as it was.

# emerge --ask --depclean sys-apps/sysvinit

With a clean slate, I rebooted again and was pleasantly surprised. Everything seems to be well on my system.. Well, almost!

sysvinit had disappeared along with shutdown, reboot, halt, poweroff, etc :( So I recreated them :)

# vi /usr/local/sbin/runit-shutdown
#!/bin/sh
case "$(basename $0)" in
  reboot) /sbin/runit-init 6 ;;
  shutdown|poweroff|halt)
    /sbin/runit-init 0 ;;
esac
# cd /sbin
# ln -s /usr/local/runit-shutdown shutdown
# ln -s /usr/local/runit-shutdown poweroff
# ln -s /usr/local/runit-shutdown halt
# ln -s /usr/local/runit-shutdown reboot

And all is well again. Powerbutton is working, as are my other i3 keybindings.

As the runit article on gentoo wiki says:
It can be used in conjunction with OpenRC as an alternative to sysvinit or even replacing OpenRC as service manager.
Runit can also replace OpenRC as the service manager.
which means runit can do everything on it's own. I have seen it being very dependable & stable in voidlinux.

Now why didn't the linux lords consider lean, clean & simple runit, when deciding about systemd?

I am usually very critical of systemd. But kudos where it is due, for systemd removing much accumulated garbage/cruft like *bus *kit etc.

For now, I will keep openrc as service manager, and runit as system init. Too much hacking at the gentoo core might take me too far away for any troubleshooting.

$ pidof runit
1

No comments:

Post a Comment

most viewed