Lucid, Upstart & Bridge Networking

New server arrived last week. Installed lucid (Ubuntu 10.04) and planned to run some VMs there with werdz‘s awesome rbvm.

Spent my first few hours at the machine tripping up over this nasty bug, but I’ll save that for a separate rant, this is a rant just about upstart.

Upstart is the kind of thing that’s great for laptops, they boot often, and you want them to boot quickly. Servers don’t boot quickly, they have network cards, remote access cards, raid controllers and other junk to initalize when they start. Because of this, trying to start everything on a system in parallel adds massive complexity without having anywhere near the same effect on the overall boot time.

Apart from this upstart, as it is, is half baked. It’s not ready to be included for a server distribution to go into production for 5 years. Most of the important services I have running here (bind, exim, apache, nginx) don’t even come with upstart configs, so half the system is still relying on old init scripts anyway.

The man page for mountall(8) sums it up pretty well:

This is a temporary tool until init(8) itself gains the necessary flexibility to perform this processing; you should not rely on its behaviour.

I noticed that after enabling bridge networking (for rbvm) on Monday that the dhcp server was no longer starting. After some investigation I concluded this was because of the delay between upstart finishing bringing up the network, and br0 actually being ready (about 15 seconds).

Writing an upstart config for dhcp didn’t help, it still ran before br0 was up, even though it was dependent on ‘started networking’. The only solution I could come up with was to add a prestart script to force upstart to wait before starting the dhcp server. This is what I came up with.

# dhcp3-server

description “DHCP Server”

start on (started networking and started dbus)
stop on (stopping networking)

expect fork

pre-start script

brstat() {
ifconfig |grep -c $BR_INTERFACE
return 0


while [ $BRSTAT -lt 1 ]; do
sleep 2

# allow dhcp server to write lease and pid file
mkdir -p /var/run/dhcp3-server
chown dhcpd:dhcpd /var/run/dhcp3-server
if [ ! -e /var/lib/dhcp3/dhcpd.leases ]; then
touch /var/lib/dhcp3/dhcpd.leases
chown dhcpd:dhcpd /var/lib/dhcp3 /var/lib/dhcp3/dhcpd.leases
if [ -e /var/lib/dhcp3/dhcpd.leases~ ]; then
chown dhcpd:dhcpd /var/lib/dhcp3/dhcpd.leases~

end script

exec /usr/sbin/dhcpd3 -q -cf /etc/dhcp3/dhcpd.conf

Why the need for the brstat() function? Upstart executes all it’s scripts with ‘/bin/sh -e’, so grep returning 1 caused the script to fail. The documentation didn’t indicate any way to change that behaviour.

After all that effort, I noticed the same problem was affecting ircd-hybrid this morning, so I’ve set a similar hack to run from /etc/rc2.d before anything else, to ensure none of the init scripts will run without the interface being up.

Posted September 7th, 2010 in Linux.

Leave a response: