#!/bin/sh # # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> # All rights reserved. # # fastcgi.sh # Runs catalyst based application's fastcgi script via daemontools' # softlimit script. You should call this script from a specific 'run' # script like so # # #!/bin/sh # /path/to/fastcgi.sh -s myapp.mydomain.com # args=`getopt s:d:m:n:g: $*` if [ $? -ne 0 ]; then echo <<EOM Usage: fastcgi-run.sh [options] -s: service name. -d: data directory -m: max memory size as passed to softlimit(3) -n: number of processes to spawn -g: group name to run script as EOM exit 2 fi set -- $args for i do case "$i" in --) shift; break;; -s) SERVICE="$2"; shift; shift;; -d) DATADIR="$2"; shift; shift;; -m) MAXMEMORY="$2"; shift; shift;; -n) NUMPROCS="$2"; shift; shift;; -g) GROUP="$2"; shift; shift;; esac done if [ -z $SERVICE ]; then echo "No service defined." exit 1; fi if [ -z $DATADIR ]; then DATADIR="/var/tmp/$SERVICE" fi if [ -z $MAXMEMORY ]; then MAXMEMORY=150000000 fi if [ -z $NUMPROCS ]; then NUMPROCS=10 fi if [ -z $GROUP ]; then GROUP=www fi SOCKET="$DATADIR/fastcgi.socket" if [ ! -d $DATADIR ]; then echo "$DATADIR does not exist. Creating..." mkdir $DATADIR if [ $? -ne 0 ]; then echo "Failed to create $DATADIR" exit 1; fi chmod a+rwx $DATADIR fi cd /www/$SERVICE if [ -z $SCRIPT ]; then SCRIPT=`find script -name '*_fastcgi.pl'` fi if [ -z $SCRIPT ]; then echo "No suitable script found" exit 1; fi exec 2>&1 \ setuidgid $GROUP \ softlimit -m $MAXMEMORY \ $SCRIPT -e -l $SOCKET -n $NUMPROCS