Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created June 29, 2011 09:21
Show Gist options
  • Select an option

  • Save PyYoshi/1053506 to your computer and use it in GitHub Desktop.

Select an option

Save PyYoshi/1053506 to your computer and use it in GitHub Desktop.
#!/bin/sh
# cat /etc/init.d/test_app
SPAWNFCGI="/usr/bin/spawn-fcgi"
SPAWNAPP="/usr/local/bin/test_app/test.fcgi"
APPNAME="test"
IP="127.0.0.1"
PORT="9000"
PID="/var/run/spawn-fcgi-test.pid"
USER="www-data"
GROUP="www-data"
spawn_start() {
if [ ! -x ${SPAWNFCGI} ]; then
echo "Can not execute spawn-fcgi, exiting ..."
exit 1
fi
if [ ! -x ${SPAWNAPP} ]; then
echo "Can not execute ${APPNAME} FCGI, exiting ..."
exit 1
fi
if [ -s ${PID} ]; then
echo "${APPNAME} FCGI is already running?"
exit 1
fi
echo "Starting ${APPNAME} FCGI ..."
${SPAWNFCGI} -f ${SPAWNAPP} -a ${IP} -p ${PORT} -u ${USER} -P ${PID}
}
spawn_stop() {
if [ ! -f ${PID} ]; then
echo "No ${APPNAME} FCGI process found, exiting ..."
else
echo "Stopping ${APPNAME} FCGI ..."
kill -QUIT $(cat ${PID})
if [ -f ${PID} ]; then
/bin/rm -f ${PID}
fi
fi
}
spawn_restart() {
spawn_stop
sleep 3
spawn_start
}
case "$1" in
start)
spawn_start
;;
stop)
spawn_stop
;;
restart)
spawn_restart
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment