Upstart can now replace sysvinit

Today I reached another milestone in the development of upstart, the packages in universe can now replace the existing sysvinit package.

Before trying this, make sure your installation is up to date as we’ve had to split out some parts of sysvinit into a new sysvutils package. If you’re up to date, and want to try it out, install the upstart and upstart-compat-sysv packages from universe.

Note that the first reboot after you’ve installed the packages (from sysvinit to upstart) will be a little tricky … use reboot -f.

If your system boots and shuts down normally, everything’s working just fine. Note that both will be somewhat more quiet than you’re used to, unless you have usplash running.

Throughout the rest of this entry, I’ll try to answer some of the questions and comments that I’ve received since the last post.

Events

As I talked about previously, upstart is an event-based init daemon. Events are the primary force for having your services and tasks started and stopped at the appropriate time and in the appropriate order.

So what are events and where do they come from? (Note that this part is under development, so may change in later releases).

Events are just simple strings that may be sent by any process when something it is tracking the state of changes. They have no state or longevity, and if, when queued, they do not cause any job state changes, then they have no effect unless they are sent again.

Jobs can list which events cause them to be started if they are not already running and which events cause them to be stopped if they are running. Multiple start and stop events may be listed, in which case the first to occur changes the job until the next one occurs.

upstart itself generates the following system events:

  • “startup”, on system boot.
  • “shutdown”, when the system is about to be shut down.
  • “stalled”, when there are no jobs running and no events in the queue.

The shutdown tool included in the package also causes one of the following events to be sent once the “shutdown” event has been handled:

  • “reboot”,
  • “halt”,
  • “poweroff”,
  • “maintenance” (aka. going into “single user” mode),
  • any user-defined event with shutdown -e event.

Jobs also generate events whenever they change state, this is the primary source of events for ordering:

  • “jobname/start”, when the job is first started.
  • “jobname/started”, once the job is running.
  • “jobname/stop”, when the job is first stopped.
  • “jobname/stopped”, once the job has stopped.
  • “jobname”, for services this is generated once it is running; for tasks this is generated once it has finished.

And as mentioned, any other process on the system may send events through the control socket or just by using initctl trigger EVENT. For now this is just the event string, however it’s intended that the event may include other details including environment variables and even file descriptors.

Typical example

To clarify how it all hangs together, here’s an example (using fictional names) of how the tasks and events can be arranged to provide race-free mounting of filesystems.

  • “udev” service started on the “startup” event.
  • udev daemon is configured to send a “new-block-device” event whenever a new block device is added to the system.
  • “checkfs” task is started on the “new-block-device” event to check the filesystem.
  • “mountfs” task is started when the “checkfs” task has finished and mounts the filesystem if listed in /etc/fstab
  • “filesystem-mounted” event is generated whenever a filesystem is mounted.
  • “fstab” task is started on the “filesystem-mounted” event, it checks the list of mounted filesystems against /etc/fstab and if all are mounted, generates the “writable-filesystem” event.
  • other services and tasks would be started on the “writable-filesystem” event.

By breaking this job into these small tasks, we can see how the pieces fit together. Because everything is now done on events, there are no race conditions; we know that any filesystem listed in /etc/fstab will be checked and mounted.

The only reason they wouldn’t be is if there’s an error of some kind, and that means you have larger problems anyway and the system administrator would have a shell to fix it. Of course, the moment they finish checking the filesystem and mount it, the boot process would carry on.

There’s no reason that any of these events need to be generated by the upstart daemon itself, it can receive them from any other daemon on the system such as udev, acpid, etc. This keeps the focus of the init daemon narrow.

A large part of the future development will be working out exactly what kinds of events we want init itself to generate, what kinds we want to come from elsewhere, and what the contents of an event can be.

Getting Involved

If you want to get involved with trying to nudge the direction of upstart development, you can join the upstart-devel mailing list at http://lists.netsplit.com/.

Or if you just want to grab the source code, tarballs are published at http://people.ubuntu.com/\~scott/software/upstart/ and the bzr archive is at http://bazaar.launchpad.net/\~keybuk/upstart/main

5 Comments

  1. Mikael:

    – “checkfs” task is started on the “new-block-device” event to check the filesystem. –

    How will checkfs know *which* filesystem to check?

  2. Nico Dietrich:

    Hm, is there actually no code or am too stupid to use bazaar for a simple checkout??

    I’m doing
    `bzr co http://bazaar.launchpad.net/~keybuk/upstart/main`

  3. Scott James Remnant:

    You want “bzr branch”, not “bzr co”

  4. Steve Parker:

    So, presumably in the example provided, the starting of udev is akin to Solaris’s svcadm starting a service?

    In other words, a service such as sshd would be started in the same way as udev is started - by an explicit operator command that sshd should be started on boot and stopped on shutdown?

    What security considerations are there in converting to Upstart? Access to config files can be controlled in the same way as access to /etc/init.d/ scripts, but if anybody can “initctl trigger event”, then initctl will need to be very carefully written (maybe with the help of sudo?)

    Steve

    (PS. I’m not sure the “x days later” feature is working on the blog; the original post was (as of now, 4th Oct) 12 days ago, but your last most was “30 days later”)

  5. Howard Coles Jr:

    When was this Blog entry actually written? It had a date of Oct. 4, but now shows Sept. 22. I’m kinda’ confused here.

    But, on the topic of Upstart, it appears to have a lot of promise. However, my concern is that we’re going to see a lot of branching in differing startup methods across various distros. What interest has been shown by other distro folks? (say openSUSE, fedora, etc.)

    The other question is what about runlevels. How do we set runlevel or running environments, such as runlevel three with no X or runlevel 2 (as in Debian) or runlevel 5 (as in SUSE and RedHat) with X?

    Also is there any hope the Debian folks or anyone else has decided to get with the Linux program and have the same runlevels across all distros mean the same thing?

Leave a comment