Ubuntu – Convert sysvinit/upstart init scripts to runit

dockerinit-scriptrunitsysvinitUbuntu

I am trying to migrate a currently VM-based infrastructure to a Docker-based one, using docker-baseimage, which uses runit/runsv to start and supervise system services. Now while it is apparently very easy to install a self-written Python program as a service, I am struggling to convert the /etc/init.d/* scripts to runit services.

Sometimes it is rather easy and there is also a list at http://smarden.org/runit/runscripts.html, but some of those scripts don't work with (the latest version of) Ubuntu paths and also I am wondering if I should sometimes embed the process in a chroot or have it run as a different user.

So, is there a safe and reliable way to convert the init scripts found in Ubuntu into simple runit-runnable scripts?

Best Answer

The Short Answer

For the time being, no, there is no automated method specific to runit.

The Long Answer

There have been several approaches to resolving this.

Using Pre-Built Scripts

The first is to have a pre-built set of scripts. These can be extracted from other projects. Void Linux uses runit as its base init and supervisor, so it might be of interest. There is a project on Github called runit-scripts that might have some of what you need. And I will make a shameless plug for my own project, supervision-scripts, which has a few of them pre-baked and ready, although the project is still being developed.

Using A Framework

The second is to provide a framework that eases the transition of writing scripts. Ignite is a possibility. Also, Toki Clover's Supervision Script Framework (not to be confused with my own project) may provide what you seek as well. In this case, there are no pre-built definitions, but you get bits and pieces of shell script (and possibly other programs) to help you make this transition easier.

Borrowing Existing Scripts and Tools

The third is to borrow scripts from other projects. This means going out and really hunting for them. There are a few out there, but you have to really look.

Doing it the hard way

And finally, you sometimes just have to write it yourself. Frankly, if you're desperate, make a copy of the original /etc/init.d/(whatever) file, set it aside, and edit the file. Typically, at the bottom of a init.d script, you'll find a CASE statement & friends, and from there you can see if there are any weird baked-in command line switches that shouldn't be there but are. Don't bother with anything beyond what is inside start) and stop) in this because they don't apply when using a supervisor. Look around and see if it needs a /var/run/(whatever) directory set up, that's always important too (don't forget to set ownership if you create it!). And towards the top, if the author did it right, there's usually a set of environment variables that contain the real daemon name, along with its options. From there you can usually cobble together a small script quickly.

Related Question