2 # /etc/init.d/mediagoblin-celery-worker
4 ## LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
5 # To the extent possible under law, Joar Wandborg <http://wandborg.se> has
6 # waived all copyright and related or neighboring rights to
7 # mediagoblin-celery-worker. This work is published from Sweden.
10 # Credit goes to jpope <http://jpope.org/> and
11 # chimo <http://chimo.chromic.org/>. From which' Arch init scripts this is
15 # Provides: mediagoblin-celery-worker
16 # Required-Start: $network $named $local_fs
17 # Required-Stop: $remote_fs $syslog $network $named $local_fs
18 # Should-Start: postgres $syslog
19 # Default-Start: 2 3 4 5
21 # Short-Description: MediaGoblin Celery task processor init script
22 # Description: This script will initiate the GNU MediaGoblin Celery
26 ################################################################################
28 # to suit your environment
29 ################################################################################
30 MG_ROOT
=GMG_PATH_TOKEN
/mediagoblin
32 ################################################################################
34 # You probably won't have to change anything else.
35 ################################################################################
39 DAEMON_NAME
=mediagoblin-celery-worker
42 MG_CELERYD_BIN
=$MG_BIN/celery\ worker
43 MG_CONFIG
=$MG_ROOT/mediagoblin_local.ini
44 MG_CELERY_CONFIG_MODULE
=mediagoblin.init.celery.from_celery
45 MG_CELERYD_PID_FILE
=/var
/run
/mediagoblin
/$DAEMON_NAME.pid
46 MG_CELERYD_LOG_FILE
=/var
/log
/mediagoblin
/$DAEMON_NAME.log
48 set_up_directories
() {
49 install -o $MG_USER -g users
-d -m 755 /var
/log
/mediagoblin
50 install -o $MG_USER -g users
-d -m 755 /var
/run
/mediagoblin
55 # Include LSB helper functions
56 .
/lib
/lsb
/init-functions
68 if [ -z "$pid" ]; then
69 log_action_msg
"Could not get PID. Aborting"
74 while ps ax |
grep -v grep |
grep $pid > /dev
/null
; do
76 seconds
=$
(expr $seconds + 1)
77 if [ $seconds -ge $kill_at ]; then
78 log_action_msg
"Failed to shut down after $kill_at seconds. Aborting"
91 while ! [[ -f $pidfile ]]; do
93 seconds
=$
(expr $seconds + 1)
95 if [ $seconds -ge $kill_at ]; then
96 log_action_msg
"Can't find the PID file," \
97 " the application must have crashed."
105 # Discard any errors from cat
106 cat $MG_CELERYD_PID_FILE 2>/dev
/null
111 # Start the MediaGoblin celery worker process
112 log_daemon_msg
"Starting GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
113 if [ -z "$(getPID)" ]; then
114 # TODO: Could we send things to log a little bit more beautiful?
115 su
-s /bin
/sh
-c "cd $MG_ROOT && \
116 MEDIAGOBLIN_CONFIG=$MG_CONFIG \
117 CELERY_CONFIG_MODULE=$MG_CELERY_CONFIG_MODULE \
119 --pidfile=$MG_CELERYD_PID_FILE \
120 -f $MG_CELERYD_LOG_FILE 2>&1 >> $MG_CELERYD_PID_FILE" \
121 - $MG_USER 2>&1 >> $MG_CELERYD_LOG_FILE &
125 wait_for_pidfile
$MG_CELERYD_PID_FILE
127 log_end_msg
$CELERYD_RESULT
129 # Failed because the PID file indicates it's running
130 log_action_msg
"PID file $MG_CELERYD_PID_FILE already exists"
135 log_daemon_msg
"Stopping GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
136 if [ -z "$(getPID)" ]; then
137 # Failed because the PID file indicates it's not running
138 log_action_msg
"Could not get PID"
144 wait_for_death $
(getPID
)
152 if ! [ -z "$(getPID)" ]; then
153 echo "$DAEMON_NAME start/running, process $(getPID)"
155 echo "$DAEMON_NAME stopped."
159 echo "Usage: $0 {restart|start|stop|status}"