2 # /etc/init.d/mediagoblin-celeryd
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-celeryd. 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-celeryd
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=/srv/mediagoblin
31 ################################################################################
33 # You probably won't have to change anything else.
34 ################################################################################
38 DAEMON_NAME=mediagoblin-celeryd
42 MG_CELERYD_BIN=$MG_BIN/celeryd
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
59 # Discard any errors from cat
60 cat $MG_CELERYD_PID_FILE 2>/dev/null
65 # Start the MediaGoblin celeryd process
66 log_daemon_msg "Starting GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
67 if [ -z "$(getPID)" ]; then
68 su -s /bin/sh -c "cd $MG_ROOT && \
69 MEDIAGOBLIN_CONFIG=$MG_CONFIG \
70 CELERY_CONFIG_MODULE=$MG_CELERY_CONFIG_MODULE \
72 --pidfile=$MG_CELERYD_PID_FILE \
73 -f $MG_CELERYD_LOG_FILE" \
74 - $MG_USER 2>&1 > /dev/null &
78 # Sleep for a while until we're kind of certain that celeryd has
79 # had it's time to initialize
81 while ! [ "X$CELERYD_RESULT" != "X" ]; do
82 log_action_msg "Tried $TRIES time(s)"
87 log_end_msg $CELERYD_RESULT
89 # Failed because the PID file indicates it's running
90 log_action_msg "PID file $MG_CELERYD_PID_FILE already exists"
95 log_daemon_msg "Stopping GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
96 if [ -z "$(getPID)" ]; then
97 # Failed because the PID file indicates it's not running
102 if [ $? -gt 0 ]; then
116 if ! [ -z "$(getPID)" ]; then
117 echo "$DAEMON_NAME start/running, process $(getPID)"
119 echo "$DAEMON_NAME stopped."
123 echo "Usage: $0 {restart|start|stop|status}"