Created
March 21, 2013 03:48
-
-
Save stojg/5210543 to your computer and use it in GitHub Desktop.
/etc/init.d/phpnaut
This file contains 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 | |
# | |
# chkconfig: 345 80 20 | |
# description: Running one resque worker | |
# | |
# start of configuration | |
RUN_USER=www-data | |
RUN_GROUP=$RUN_USER | |
APP_DIR=/path/to/framework/cli-script.php | |
# // end of configuration | |
APP_NAME=php-resque | |
PID_DIR=/var/run/$APP_NAME | |
PID_FILE=$PID_DIR/$APP_NAME.pid | |
LOCK_FILE=/var/lock/subsys/$APP_NAME | |
LOG_DIR=/var/log/$APP_NAME | |
if [ "$1" == "daemon" ]; then | |
if [ `whoami` != $RUN_USER ]; then | |
echo "You are not $RUN_USER, bye!" | |
exit 1 | |
fi | |
cd $APP_DIR | |
VERBOSE=$VERBOSE nohup /bin/env php $APP_DIR dev/resque/run queue=* >> $LOG_DIR/$APP_NAME.log 2>&1 </dev/null & | |
echo -n "$!" > $PID_FILE | |
exit | |
fi | |
. /etc/rc.d/init.d/functions | |
if [ `whoami` != "root" ]; then | |
echo "You are not root, bye!">&2 | |
exit 1 | |
fi | |
start() { | |
echo -n $"Starting $APP_NAME: " | |
mkdir -p $PID_DIR $LOG_DIR | |
chown -R $RUN_USER:$RUN_GROUP $PID_DIR $LOG_DIR | |
daemon --user=$RUN_USER --pidfile=$PID_FILE --check=$APP_NAME $0 daemon && touch $LOCK_FILE | |
} | |
stop() { | |
echo -n "Shutting down $APP_NAME: " | |
killproc -p $PID_FILE $APP_NAME | |
local RETVAL=$? | |
[ -f $LOCK_FILE ] && rm $LOCK_FILE | |
[ -d $PID_DIR ] && rmdir $PID_DIR | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop; echo | |
start | |
;; | |
status) | |
echo -n "$APP_NAME" `status -p $PID_FILE` | |
;; | |
*) | |
echo -n "Usage: $0 {start|stop|restart|status}" | |
esac | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment