Skip to content

Instantly share code, notes, and snippets.

@bjonord
Last active January 3, 2016 05:09
Show Gist options
  • Save bjonord/8414311 to your computer and use it in GitHub Desktop.
Save bjonord/8414311 to your computer and use it in GitHub Desktop.
init.d and monitrc file for resque-pool - https://github.com/nevans/resque-pool
#!/bin/sh -e
APP_NAME="xxxx"
APP_DIR="/var/www/${APP_NAME}/current"
PIDFILE="${APP_DIR}/tmp/pids/${APP_NAME}_resque"
RUN_AS="rails"
SLEEP_TIME=5
ENV="production"
STDOUT="${APP_DIR}/log/resque-pool.log"
STDERR="${APP_DIR}/log/resque-pool-error.log"
GEMFILE="BUNDLE_GEMFILE=/var/www/<app>/current/Gemfile"
CONFIG="${APP_DIR}/config/resque/pool.yml"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Resque Pool"
/bin/su - ${RUN_AS} -c "cd ${APP_DIR} && ${GEMFILE} \
bundle exec resque-pool -d -a ${APP_NAME} -p ${PIDFILE} \
-E ${ENV} -o ${STDOUT} -e ${STDERR} --config ${CONFIG}"
fi
;;
reload)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
echo "Reloading configuration file."
cat ${PIDFILE} | xargs kill -s HUP
fi
;;
graceful-stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
echo "Stopping gracefully."
cat ${PIDFILE} | xargs kill -s QUIT
fi
;;
quick-stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
echo "Stopping quickly."
cat ${PIDFILE} | xargs kill -s INT
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
echo "Stopping."
cat ${PIDFILE} | xargs kill -s TERM
fi
;;
restart)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
$0 stop
sleep ${SLEEP_TIME}
$0 start
fi
;;
*)
echo "Usage: $0 {start|stop|graceful-stop|quick-stop|restart|reload}"
exit 1
;;
esac
check process <%= application_name %>_resque
with pidfile "<%= shared_path %>/pids/<%= application_name %>_resque"
start program = "/etc/init.d/<%= application_name %>_resque start"
stop program = "/etc/init.d/<%= application_name %>_resque stop"
group <%= application_name %>_resque
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment