-
-
Save philsturgeon/1618623 to your computer and use it in GitHub Desktop.
/etc/init.d/gearman-workers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# /etc/init.d/gearman-workers | |
### BEGIN INIT INFO | |
# Provides: gearman-workers | |
# Required-Start: $network $remote_fs $syslog | |
# Required-Stop: $network $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start daemon at boot time | |
# Description: Run gearman workers | |
### END INIT INFO | |
PIDDIR=/var/run/gearman | |
start() | |
{ | |
if ! test -d ${PIDDIR} | |
then | |
mkdir ${PIDDIR} | |
fi | |
for file in /home/ubuntu/workers/*.php | |
do | |
echo "Starting worker: $file" | |
PID=`php $file &` | |
PIDFILE=${PIDDIR}/${PID}.pid | |
echo $PID > $PIDFILE | |
done | |
echo "Workers started" | |
exit 2 | |
} | |
stop() | |
{ | |
echo "Stoping workers $2" | |
for file in "${PIDDIR}/*.pid" | |
do | |
PID=`cat $file` | |
kill -9 $PID | |
done | |
exit 1 | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|force-reload) | |
start | |
stop | |
;; | |
*) | |
echo "Input [start|stop|restart|force-reload]" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a greater way to do this is as described at: http://www.bram.us/2013/11/11/run-a-php-script-as-a-servicedaemon-using-start-stop-daemon/