Published: 2024-08-27T13:05:09+02:00
runit is being removed from Gentoo.
With the removal of runit from the Gentoo package repository, I have finally been forced to migrate to something new for managing user services on a system without systemd.
Gentoo's “default” init service is OpenRC, a modern alternative to the traditional SysV init (or other SysV-esque, like upstart) that was commonplace in most Linux distros up until ~2015, when systemd started taking over basically everywhere. Today, the landscape is very different:
- Most distros use systemd. Debian, Ubuntu, Arch all use this by default, and usually ONLY support it, officially.
- These distros have often been forked specifically to remove systemd, to varying degrees of success (Devuan, Artix).
- There is a class of independent distros, like Void, that use other init systems.
Gentoo has, for a very long time, used OpenRC as its default init system. But Gentoo also has official support for systemd. Because of this dual support, the efforts of the Gentoo developers have resulted in major applications that would otherwise have hard systemd dependency being able to run on other init systems. Most notably, patches for the GNOME desktop are maintained by Gentoo developers to make it work with OpenRC.
User Services on OpenRC
One of the biggest missing features in OpenRC, for me, is user services. This is something systemd does very well. You just stick —user on a systemctl command, and you can run unprivileged services from your local user account.
User services are perfect for things like:
- syncthing
- rclone mounts
- Protonmail Bridge
They're great for anything that needs to run all the time and stay out of your way.
https://wiki.gentoo.org/wiki/OpenRC/User_services
OpenRC does not truly support user services. The best support for a “user service” with OpenRC is running a system-level service as a specific user. This is fine for basic single-user use cases, but still requires root access to modify or create new services. There are some other approaches in the wiki, but they are (in my opinion) even more hacky or complicated.
https://github.com/navi-desu/openrc/
Luckily, there is now a fork of OpenRC (called OpenRC-Navi) that adds user service support to OpenRC. The fork is available in Gentoo as sys-apps/openrc-navi. The original is available as sys-apps/openrc.
Using OpenRC-Navi User Services
Creating user services with the fork of OpenRC is straightforward; it's basically the same as creating system services.
Official User Service Guide
OpenRC Service Script Guide
In summary:
- Service scripts go in ~/.config/openrc/init.d/
- Use the —user (or -U) parameter with rc-service, rc-update, etc.
Caveats
At the time of writing, here are some issues I ran into while porting my runit scripts to OpenRC scripts:
- supervise-daemon does not currently work with user services. A permission denied error occurs.
- Paths using ~/ (tilde for home) don't work correctly. I had to specify absolute paths to avoid some odd file not found errors.
Example
Here is an example user service for an rclone mount.
The service meant to be symlinked, one for each specific rclone mountpoint to be created. For example, if you have an rclone mountpoint called nextcloud:
, then you would need to execute shell some commands like this:
ln -s ~/.config/openrc/init.d/rclone-mount ~/.config/openrc/init.d/rclone-mount.nextcloud
echo 'RCLONE_REMOTE=nextcloud:"' >> ~/.config/openrc/conf.d/rclone-mount.nextcloud
echo LOCAL_MOUNTPOINT=/mnt/nextcloud"' >> ~/.config/openrc/conf.d/rclone-mount.nextcloud
rc-update -U add rclone-mount.nextcloud default
rc-service -U rclone-mount.nextcloud start
Alternatives
Instead of using a fork of OpenRC, there are a few alternatives on a Gentoo system:
- s6: Another init system that continues to be supported.
- runit: runit might be saved by a proxy maintainerb and not removed.
Hopefully, the user service feature of OpenRC-Navi makes its way back upstream into the main version of OpenRC.
License: CC-BY-SA-4.0.
Written by: @[email protected]