Description: LSB compliant headers, status actions and ENABLED variable
 Upstream ships it's own init scripts but they lack some LSB header and the 
 (optional) "status" action. This patch fixes this and also adds a variable called ENABLED 
 in /etc/default/celeryd.
Author: Michael Fladischer <FladischerMichael@fladi.at>
Last-Update: 2012-01-18
Forwarded: no

--- a/contrib/generic-init.d/celeryd
+++ b/contrib/generic-init.d/celeryd
@@ -16,6 +16,7 @@
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: celery task worker daemon
+# Description:       Starts the Celery worker daemon for a single project.
 ### END INIT INFO
 
 #set -e
@@ -25,16 +26,18 @@
 DEFAULT_LOG_LEVEL="INFO"
 DEFAULT_NODES="celery"
 DEFAULT_CELERYD="-m celery.bin.celeryd_detach"
+ENABLED="false"
 
-# /etc/init.d/celeryd: start and stop the celery task worker daemon.
+[ -r "$CELERY_DEFAULTS" ] && . "$CELERY_DEFAULTS"
 
-CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/celeryd"}
+[ -r /etc/default/celeryd ] && . /etc/default/celeryd
 
-test -f "$CELERY_DEFAULTS" && . "$CELERY_DEFAULTS"
-if [ -f "/etc/default/celeryd" ]; then
-    . /etc/default/celeryd
+if [ "$ENABLED" != "true" ]; then
+    echo "celery daemon disabled - see /etc/default/celeryd."
+    exit 0
 fi
 
+
 CELERYD_PID_FILE=${CELERYD_PID_FILE:-${CELERYD_PIDFILE:-$DEFAULT_PID_FILE}}
 CELERYD_LOG_FILE=${CELERYD_LOG_FILE:-${CELERYD_LOGFILE:-$DEFAULT_LOG_FILE}}
 CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
--- a/contrib/generic-init.d/celeryevcam
+++ b/contrib/generic-init.d/celeryevcam
@@ -1,6 +1,6 @@
 #!/bin/bash
 # ============================================
-#  celeryd - Starts the Celery worker daemon.
+#  celeryevcam - Starts the Celery event snapshot daemon.
 # ============================================
 #
 # :Usage: /etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status}
@@ -78,12 +78,13 @@
 #       Full path to the virtualenv environment to activate. Default is none.
 
 ### BEGIN INIT INFO
-# Provides:          celeryev
+# Provides:          celeryevcam
 # Required-Start:    $network $local_fs $remote_fs
 # Required-Stop:     $network $local_fs $remote_fs
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: celery event snapshots
+# Description:       Starts the Celery event snapshots daemon for a single project.
 ### END INIT INFO
 
 # Cannot use set -e/bash -e since the kill -0 command will abort
@@ -94,13 +95,15 @@
 DEFAULT_LOG_FILE="/var/log/celeryev.log"
 DEFAULT_LOG_LEVEL="INFO"
 DEFAULT_CELERYEV="/usr/bin/celeryev"
+ENABLED="false"
 
-if test -f /etc/default/celeryd; then
-    . /etc/default/celeryd
-fi
+[ -r /etc/default/celeryd ] && . /etc/default/celeryd
+
+[ -r /etc/default/celeryev ] && . /etc/default/celeryev
 
-if test -f /etc/default/celeryev; then
-    . /etc/default/celeryev
+if [ "$ENABLED" != "true" ]; then
+    echo "celeryevcam daemon disabled - see /etc/default/celeryd."
+    exit 0
 fi
 
 CELERYEV=${CELERYEV:-$DEFAULT_CELERYEV}
@@ -197,7 +200,16 @@
               --pidfile="$CELERYEV_PID_FILE"
 }
 
-
+status () {
+    pid=$(cat "$CELERYEV_PID_FILE")
+    kill -0 $pid 1>/dev/null 2>&1
+    if [ $? -eq 0 ]; then
+        echo "celeryevcam running"
+    else
+        echo "celeryevcam not running"
+        exit 1
+    fi
+}
 
 case "$1" in
   start)
@@ -216,9 +228,12 @@
     check_dev_null
     start_evcam
     ;;
+  status)
+    status
+    ;;
 
   *)
-    echo "Usage: /etc/init.d/celeryev {start|stop|restart}"
+    echo "Usage: /etc/init.d/celeryev {start|stop|restart|status}"
     exit 1
 esac
 
--- a/contrib/generic-init.d/celerybeat
+++ b/contrib/generic-init.d/celerybeat
@@ -15,6 +15,7 @@
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: celery periodic task scheduler
+# Description:       Starts the Celery periodic task scheduler.
 ### END INIT INFO
 
 # Cannot use set -e/bash -e since the kill -0 command will abort
@@ -25,15 +26,15 @@
 DEFAULT_LOG_FILE="/var/log/celerybeat.log"
 DEFAULT_LOG_LEVEL="INFO"
 DEFAULT_CELERYBEAT="celerybeat"
+ENABLED="false"
 
-# /etc/init.d/ssh: start and stop the celery task worker daemon.
+[ -r /etc/default/celeryd ] && . /etc/default/celeryd
 
-if test -f /etc/default/celeryd; then
-    . /etc/default/celeryd
-fi
+[ -r /etc/default/celerybeat ] && . /etc/default/celerybeat
 
-if test -f /etc/default/celerybeat; then
-    . /etc/default/celerybeat
+if [ "$ENABLED" != "true" ]; then
+    echo "celerybeat daemon disabled - read /etc/default/celeryd."
+    exit 0
 fi
 
 CELERYBEAT=${CELERYBEAT:-$DEFAULT_CELERYBEAT}
@@ -125,7 +126,16 @@
                 --pidfile="$CELERYBEAT_PID_FILE"
 }
 
-
+status () {
+    pid=$(cat "$CELERYBEAT_PID_FILE")
+    kill -0 $pid 1>/dev/null 2>&1
+    if [ $? -eq 0 ]; then
+        echo "celerybeat running"
+    else
+        echo "celerybeat not running"
+        exit 1
+    fi
+}
 
 case "$1" in
   start)
@@ -144,9 +154,12 @@
     check_dev_null
     start_beat
     ;;
+  status)
+    status
+    ;;
 
   *)
-    echo "Usage: /etc/init.d/celerybeat {start|stop|restart}"
+    echo "Usage: /etc/init.d/celerybeat {start|stop|restart|status}"
     exit 1
 esac
 
