Skip to content

Commit 6b5ea62

Browse files
committed
Merge pull request resque#719 from postmodern/init.d
Added an example Ubuntu init.d script for starting resque workers.
2 parents b87c6af + 247ba05 commit 6b5ea62

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

examples/ubuntu/resque

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh -e
2+
### BEGIN INIT INFO
3+
# Provides: resque
4+
# Required-Start: $local_fs $remote_fs
5+
# Required-Stop: $local_fs $remote_fs
6+
# Should-Start: $local_fs
7+
# Should-Stop: $local_fs
8+
# Default-Start: 2 3 4 5
9+
# Default-Stop: 0 1 6
10+
# Short-Description: resque - a Redis-backed Ruby library for creating background jobs
11+
# Description: resque - a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later.
12+
### END INIT INFO
13+
14+
set -e
15+
16+
. /lib/lsb/init-functions
17+
18+
NAME="www.example.com"
19+
ROOT="/srv/APP_NAME"
20+
USER="deploy"
21+
GROUP="deploy"
22+
ENVIRONMENT="production"
23+
QUEUES="*"
24+
COUNT=2
25+
26+
BUNDLER="/usr/bin/bundle"
27+
RAKE="/usr/bin/rake"
28+
TASK="resque:work"
29+
PIDFILE="$ROOT/tmp/pids/resque_worker.%d.pid"
30+
31+
start() {
32+
local program
33+
local options
34+
35+
if test -f $ROOT/Gemfile.lock; then
36+
program="$BUNDLER"
37+
options="exec rake $TASK"
38+
else
39+
program="$RAKE"
40+
options="$TASK"
41+
fi
42+
43+
options="$options RACK_ENV=$ENVIRONMENT QUEUES=$QUEUES"
44+
45+
for i in $(seq 1 $COUNT); do
46+
pidfile=$(printf "$PIDFILE" $i)
47+
48+
if start-stop-daemon --start --background --quiet --pidfile $pidfile --chdir $ROOT --chuid $USER:$GROUP --exec $program -- $options PIDFILE=$pidfile
49+
then
50+
log_daemon_msg "Starting worker #$i for $NAME ..."
51+
else
52+
log_failure_msg "Failed to start worker #$i for $NAME!"
53+
fi
54+
done
55+
}
56+
57+
stop() {
58+
local pidfile
59+
60+
for i in $(seq 1 $COUNT); do
61+
pidfile=$(printf "$PIDFILE" $i)
62+
63+
if start-stop-daemon --stop --quiet --oknodo --pidfile $pidfile
64+
then
65+
log_daemon_msg "Stopped Resque worker #$i for $NAME"
66+
rm -f $pidfile
67+
else
68+
log_failure_msg "Failed to stop Resque worker #$i for $NAME!" >&2
69+
fi
70+
done
71+
}
72+
73+
status() {
74+
local pidfile
75+
76+
for i in $(seq 1 $COUNT); do
77+
pidfile=$(printf "$PIDFILE" $i)
78+
79+
status_of_proc -p $pidfile "rake $TASK" "$NAME worker #$i"
80+
done
81+
}
82+
83+
case "$1" in
84+
start) start ;;
85+
stop) stop ;;
86+
restart|force-reload)
87+
stop
88+
sleep 1
89+
start
90+
;;
91+
status) status ;;
92+
*)
93+
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
94+
exit 1
95+
;;
96+
esac

0 commit comments

Comments
 (0)