#!/bin/sh -e ### BEGIN INIT INFO # Provides: resque # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Should-Start: $local_fs # Should-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: resque - a Redis-backed Ruby library for creating background jobs # Description: resque - a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later. ### END INIT INFO set -u set -e . /lib/lsb/init-functions NAME="<%= application %>" ROOT=<%= current_path %> USER="<%= resque_user %>" GROUP="<%= resque_user %>" ENVIRONMENT="<%= rails_env %>" QUEUES="<%= resque_queue %>" COUNT=<%= resque_workers %> TASK="<%= resque_task %>" PIDFILE="$ROOT/tmp/pids/resque_worker.%d.pid" RBENV="<%= rbenv_install_path %>" PATH="$RBENV/shims:$RBENV/bin:$PATH" BUNDLE="$RBENV/shims/bundle" chdir $ROOT start() { local program local options program=$BUNDLE options="exec rake $TASK" options="$options RACK_ENV=$ENVIRONMENT QUEUES=$QUEUES NEWRELIC_DISPATCHER=resque" for i in $(seq 1 $COUNT); do pidfile=$(printf "$PIDFILE" $i) if start-stop-daemon --start --background --quiet --pidfile $pidfile --chdir $ROOT --chuid $USER:$GROUP --exec $program -- $options PIDFILE=$pidfile then log_daemon_msg "Starting worker #$i for $NAME ..." else log_failure_msg "Failed to start worker #$i for $NAME!" fi done } stop() { local pidfile for i in $(seq 1 $COUNT); do pidfile=$(printf "$PIDFILE" $i) if start-stop-daemon --stop --quiet --oknodo --pidfile $pidfile then log_daemon_msg "Stopped Resque worker #$i for $NAME" rm -f $pidfile else log_failure_msg "Failed to stop Resque worker #$i for $NAME!" >&2 fi done } status() { local pidfile for i in $(seq 1 $COUNT); do pidfile=$(printf "$PIDFILE" $i) status_of_proc -p $pidfile "rake $TASK" "$NAME worker #$i" done } case "$1" in start) start ;; stop) stop ;; restart|force-reload) stop sleep 1 start ;; status) status ;; *) echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac