5

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?

  • Is a sysvinit or a upstart script? Each has different structure and ability. – Braiam Dec 26 '14 at 2:21
  • I guess that's part of the question; it's not about one script, but about all init scripts I'll find along the way. docker-baseimage is Ubuntu 14.04-based, which means that I probably will find both (example: postfix init script). – tgpfeiffer Dec 26 '14 at 2:46
  • That would be quite the hurdle. I'm afraid that such method if exist, it would be very error prone, since SysV init script are basically shell scripts with some comments, while upstart are separated in stanzas/key/value pairs with some limited scripting support. I would recommend to separate both instead. – Braiam Dec 26 '14 at 2:56
  • A non-technical/automated method would be fine as well. It can involve some copy & paste and manual replacement, I just have no idea where and how to start and how I can find out the actual commands I need to run... – tgpfeiffer Dec 26 '14 at 4:12
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.