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 form:
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 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__
#!/bin/sh
exec 2>&1
exec chpst -u www-data:www-data svlogd -tt /var/log/myapp
__END__
chmod +x /etc/sv/myapp/log/run
chown -R www-data:www-data /var/log/myapp
Setup Paster:
cat > /etc/sv/myapp/run << __END__
#!/bin/sh
exec 2>&1
cd /home/myproject/source/trunk/myapp
exec chpst -u www-data:www-data paster serve production.ini
__END__
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.
Comments
cd /etc/sv/myapp/supervise
chmod 755 .
chown myproject:myproject ok control status
cat > /etc/sv/myapp/run << __END__
#!/bin/sh
exec 2>&1
mkdir -p /var/run/myapp
chown -R www-data:www-data \
/var/run/myapp
cd /home/myproject/source/trunk/myapp
exec chpst -u www-data:www-data \
paster serve production.ini
__END__
import subprocess
r = 3
while r == 3:
r = subprocess.call(["python2.5","myscript.py"])
Huh? What does that have to do with launching a daemon on boot?
Very helpful. Thanks!
Ah right. Nothing to do with launching on boot, but ...
> I wanted something that could restart my process as necessary, so I decided against
... if your app responds properly to a appropriate SIG to restart, or roll your own signals for controlling the app. We did this with our web apps and decided on this code instead of Supvervisor due to the simplicity of it.
If wanting an easy way to restart individual applications, then use mod_wsgi daemon mode and touching the WSGI application script file will cause a restart of that application on next request without needing to restart Apache. With daemon mode you can even run applications as specific users.
Thanks for the advice. I decided to use Nginx and proxy to Paster. I'll keep mod_wsgi in mind, though.
The equivalent supervisor program config for this setup is something like:
[program:pylons]
user = www-data
directory = /var/run/myapp
command = paster serve production.ini
Wrt supervisor log rotation, maybe the problem is that it "just happens" without needing to set up an external log rotation program. Since supervisor captures the stdout (and stderr) of its children, it handles log rotation itself.
As long as the program you're running just sends stuff to stdout or stderr the following things are true:
- if the reason you want to set up log rotation is that you don't want your disk to fill up, but you don't really care too much about how long old logs are kept for, do nothing special to set up under supervisor. It will send log output to a temporary location.
- if you actually care about keeping backups of the log file and logging to a particular location, you need to set "stdout_logfile_maxbytes" and "stdout_logfile_backups" and perhaps "stdout_logfile" (to put the log in in a particular place) for the program you're running.
I don't know what Mike's problems with it were.
BTW, in general, I was really impressed with Supervisor's documentation.
Does upstart take care of restarting daemons and log rotation? It might. I don't know.