Sunday, April 6

Upstart

I had an occasion to deal with "upstart" last week.

Upstart is a project which replaces "init". The design intent is pretty obvious: allow independent packages to have components which run at system boot. The expressed intent is somewhat different: add new "scanning" functionality to init (https://en.wikipedia.org/wiki/Upstart#Rationale).

Wait, what?

In other words, upstart has reduced functionality from sysv init. It no longer supports /etc/inittab and that's probably a good thing. Simplicity is a virtue. But documentation is hard to find and with all of its modules and added features (it also has added features) it can take some study before you can do anything useful with it.

A typical use for /etc/inittab was: you add a line specifying some program to run, and init runs it for you. If the program exits, init will restart it for you. Nice and simple.

For example you might add a line like this:

work:23:respawn:/bin/su username -c /home/username/bin/dowork

This would run /home/username/bin/dowork as the user 'username'. There's more details here, but that's the gist of it. And if the program exits, init would start it up again (if you read the man page for inittab you can see all sorts of details about this kind of thing).

Well, with upstart, there's more you have to do.

First, you have to create a configuration file such as /etc/init/work.conf

For this example that file might contain:
respawn
exec /bin/su username -c /home/username/bin/dowork

And then you also need to somehow get this started at machine boot. One possibility is to add a line to /etc/rc.local like:

service work start

Another possibility involves creating /etc/init.d/work (which might be the same) and then symbolically linking it from /etc/rc2.d/S99work and so on... You can get fancy here and create start/stop/restart commands. You probably do not want to get into this kind of complexity unless you are building packages for other people to use.

And, of course, there's lots more possibilities.

But upstart currently is not documented very well, in my opinion. Specifically, there is nothing in the manual page for upstart which even hints at the need to run the service program at boot time to achieve what init does automatically. Instead, the documentation reads like it would start the service automatically when a conf file was placed in /etc/init/. (And that might have been true for some versions of upstart - but it's not true for the version I'm using in ubuntu version 13.)

And this is something that both the free software communities and the professional software communities need to get better at: documenting things properly. And maybe this is something colleges need to do a better job of teaching.

It's really hard, as a developer, to think from the viewpoint of the user. And it's really easy for the user to not connect with the developer (note that I've not connected with any upstart developers about this issue - at least, not yet). So this is a difficult issue to think about, sometimes.



No comments:

Post a Comment