All My Brain Where stuff from my brain lands

October 8, 2007

Gentoo Init Scripts for Cherrypy

A few of the web applications I am hosting/developing are written with TurboGears which uses Cherrypy as its applications server. I have a couple things that need fixed for hosting CherryPy web applications on my Gentoo systems. First, there are no init scripts for CherryPy. Second, I’m running mulitple web applications per machine. I run them as different users with virtual python environments to keep web applications stepping on each others toes.

You can customize the logging for a TurboGears application to have not logging to standard out, but you still have to deal with the python CherryPy process not running as a daemon. I chose rather to run the application in a screen session.

First, a quick script to start my web application in its virtual python environment in my web applications directory.
#!/bin/bash
PATH=/home/<myuser>/bin:$PATH
cd `dirname $0`
./start-<mywebapp>.py prod.cfg

And next, a real simply startup script that starts and stops the application in a screen session.

#!/sbin/runscript
depend() {
need net
}
start() {
su -l $APPUSER -c "screen -S $SESS_NAME -d -m /$APP_DIR/$SCRIPT_NAME"
}
stop() {
su -l $APPUSER -c "screen -S $SESS_NAME -X kill"
}

The variables can go in /etc/conf.d/<app_name> where the <app_name> is the same name as the init.d script. They will automatically be sourced and passed to the init script. For more information on Gentoo init scripts, check here.

Powered by WordPress

css.php
%d bloggers like this: