This init.d script for starting a Pylons application should be usable on Fedora, Red Hat and CentOS Linux distributions. I have personally tested it on Fedora. I tried to maintain the look and feel of other Red Hat style start scripts as much as possible. To customize it for your Pylons application, simply change the parameters marked in "<>" brackets. Also, you will want to verify that the paths to Python and Paster are correct and modify the pid, lock and log paths if desired. Note that this script starts with "reload" enabled. You can simply remove that line if you don't need it.
To use chkconfig to start the application in default run level modes, after copying this script to /etc/rc.d/init.d/<app_name>, do the following:
chkconfig --add <app_name>
chkconfig <app_name> on
chkconfig --list <app_name>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/bin/bash # # <app_name> Startup script for the <app_name> Pylons app # # chkconfig: - 90 15 # description: <app_name> is a Pylons-based web application. # Source Red Hat function library. . /etc/rc.d/init.d/functions RETVAL=0 DESC=<app_name> APP_PATH=<path_to_app> PYTHON=/usr/bin/python PASTER=/usr/bin/paster CONFIG=<your_ini_config_file_name> USER=<user_to_run_as> GROUP=<group_to_run_as> LOG_FILE=$APP_PATH/$DESC.log PID_FILE=$APP_PATH/$DESC.pid LOCK_FILE=$APP_PATH/$DESC.lock OPTIONS=" serve -q --daemon \ --user=$USER \ --group=$GROUP \ --reload \ --log-file=$LOG_FILE \ --pid-file=$PID_FILE \ $CONFIG" start() { echo -n $"Starting $DESC: " status if [[ $STATUS =~ 'Server running' ]] then # if already started, echo paster status echo $STATUS else cd $APP_PATH daemon $PYTHON $PASTER $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch $LOCK_FILE return $RETVAL fi } stop() { echo -n $"Stopping $DESC: " status if [[ $STATUS =~ 'No PID' ]] then # if already stopped, echo paster status echo $STATUS else cd $APP_PATH $PYTHON $PASTER serve --stop-daemon --pid-file=$PID_FILE RETVAL=$? [ $RETVAL = 0 ] && echo_success && rm -f $LOCK_FILE echo fi } status() { cd $APP_PATH STATUS=`$PYTHON $PASTER serve --status --pid-file=$PID_FILE $CONFIG` } case "$1" in start) start ;; stop) stop ;; status) status echo $STATUS ;; restart) stop start ;; *) N=/etc/init.d/$DESC echo "Usage: $N {start|stop|status|restart}" >&2 exit 1 ;; esac exit 0 |