Quantcast

How to run lighttpd under upstart

Upstart is Ubuntu’s init.d replacement. It greatly simplifies writing init.d scripts and has a great respawn feature similar to daemontool’s supervise or monit. And it comes with Ubuntu by default.

For some reason, almost no one uses upstart. Even Ubuntu’s services use traditional /etc/init.d scripts instead of upstart scripts. I think this might be due to upstart’s non-existent documentation. There is no man page for upstart, and multiple people I know who have read the online docs somehow missed the three important commands that control upstart jobs: /sbin/start, /sbin/stop, and /sbin/status!

Here is how it works: put an upstart script in /etc/event.d. Let’s call it /etc/event.d/foo. This script is now immediately available under upstart. Just type sudo start foo. That’s it.

I converted Ubuntu’s /etc/init.d/lighttpd script to a much shorter upstart script. The big advantage of this is upstart will restart lighttpd if it dies for some reason. This is what the upstart script looks like:

#this is an upstart script that  starts lighttpd
 
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
 
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
 
respawn
exec sudo -u www-data lighttpd -D -f /etc/lighttpd/lighttpd-infobase.conf

That’s it! Save this script as /etc/event.d/OL-lighttpd, and then type sudo start OL-lighttpd. You can kill off the lighttpd process and it will get restarted.

If you want to configure your lighttpd to write out a pid file, you can use pre-start and post-stop script to prepare and clean up the pid file:

#this is an upstart script that  starts lighttpd
 
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
 
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
 
 
pre-start script
    #make sure there is a place to write the pid file (optional):
    mkdir -p /var/run/lighttpd > /dev/null 2> /dev/null
    chown www-data:www-data /var/run/lighttpd
    chmod 0750 /var/run/lighttpd
end script
 
respawn
exec sudo -u www-data lighttpd -D -f /etc/lighttpd/lighttpd-infobase.conf
 
post-stop script
    #remove pid file (optional)
    #add server.pid-file = "/var/run/lighttpd/lighttpd.pid" to lighttpd.conf file to have it generate the pid file
    rm -f /var/run/lighttpd/lighttpd.pid
end script

If you want to stop lighttpd, just type sudo stop OL-lighttpd. You can also type sudo initctl list for a list of all jobs under upstart.

Let me see… I think I can pencil you in between Ubuntu installs.

I did two things last week: sleep, and install Ubuntu. That’s all I did. Acutally, I didn’t really sleep very much, because I was busy installing Ubuntu about 54,000 times. Here, I made a chart:

Liveblogging an Ubuntu 7.10 installation

Photo_102.jpg

Bob, Shag and I are trying to move our book scanning hardware to Ubuntu 7.10 – the Gutsy Gibbon. It’s a ridiculous process, and our hardware is crap. Here are some notes:

  • chai:20 (4:20) – Started up the installer app on the live cd. Unfortuantely the screen rez is 800×600, so we can’t see the important back/next/ok buttons on the bottom of the installer panel. What kind of installer requires greater than 800×600 screen rez?
  • chai:23 – Somehow, by logging the Live CD user out and fucking with the screen rez, we got the screen to display a larger screen res, but we can’t see the entire desktop on our screen. Moving the mouse around seems to pan the desktop, which would kinda work, if we could see the mouse cursor.
  • chai:25 – We are asked for the timezone, and San Francisco isn’t one of the available options. Los Angeles is. However, we opt to move to La Paz.
  • chai:30 – It is now officially time for chai.
  • chai:40 – We have found that starting a lot of xeyes processes lets us estimate where the invisible mouse cursor should be. There are fifty eyeballs on our screen
  • chai:45 – Bob starts playing minesweeper
  • chai:48 – Someone figures out that this version of xeyes lets us resize the window, so there is a GIANT EYEBALL staring at me
  • chai:50 – Installation done, rebooting!
  • Mouse works after reboot! Now to try and scan books!

Photo_101.jpg

Photo_10.jpg