[Baypiggies] Dumb "keep it running" script

Shannon -jj Behrens jjinux at gmail.com
Thu Sep 24 08:50:55 CEST 2009

>From my blog: http://jjinux.blogspot.com/2008/07/linux-running-paster-under-runit-on.html

Linux: Running Paster under runit on Ubuntu

I needed to setup Paster, Pylon's default Web server, on Ubuntu. I had
a heck of a hard time deciding whether I wanted to run it under
Supervisor, daemontools, monit, runit, or a handmade rc script.

Supervisor has been getting a lot of press lately, but I couldn't find
a standard way of starting it on Ubuntu. This seemed like a chicken
and egg problem. Furthermore, I knew my buddy Mike Orr was having a
hard time getting log rotation working with it.

I wanted something that could restart my process as necessary, so I
decided against a standard rc script, even though I knew Paster has a
--monitor-restart option. I eventually settled on runit. I had used it
in the past, the directions were clear, and it just "felt right". My
buddy Allan Bailey even gave me a quick cheat sheet.

If anyone can show me a nice comparison of all of these options, I'd
love to read it. I wasn't able to find much on Google that compared
them all.

Anyway, here's what I did in outline (i.e. indented) form:

Setup myapp under runit:
  Setup logging:
    mkdir -p /etc/sv/myapp/log
    mkdir -p /var/log/myapp

    cat > /etc/sv/myapp/log/run << __END__

exec 2>&1
exec chpst -u www-data:www-data svlogd -tt /var/log/myapp

    chmod +x /etc/sv/myapp/log/run
    chown -R www-data:www-data /var/log/myapp
  Setup Paster:

    cat > /etc/sv/myapp/run << __END__

exec 2>&1
cd /home/myproject/source/trunk/myapp
exec chpst -u www-data:www-data paster serve production.ini

    chmod +x /etc/sv/myapp/run
    ln -s /etc/sv/myapp /etc/service/
  Setup /var for the app:
    mkdir /var/run/myapp
    chown -R www-data:www-data /var/run/myapp
    Edited various directory settings in production.ini.

It looks complicated, but really it isn't.  runit has a lot of
advantages such as good log rotation and it doesn't involved polling
some pid file.  If the command dies, runit gets notified by waitpid,
and will restart the command *immediately*.

Happy Hacking!

In this life we cannot do great things. We can only do small things
with great love. -- Mother Teresa

More information about the Baypiggies mailing list