Browse Source

Adds CELERY_APP and CELERY_BIN options to init scripts and updates daemonization tutorial. Closes #1012

Ask Solem 12 years ago
parent
commit
af5862f514
3 changed files with 115 additions and 38 deletions
  1. 90 33
      docs/tutorials/daemonizing.rst
  2. 9 2
      extra/generic-init.d/celerybeat
  3. 16 3
      extra/generic-init.d/celeryd

+ 90 - 33
docs/tutorials/daemonizing.rst

@@ -42,7 +42,9 @@ Example configuration
 
 This is an example configuration for a Python project.
 
-:file:`/etc/default/celeryd`::
+:file:`/etc/default/celeryd`:
+
+.. code-block:: bash
 
     # Name of nodes to start
     # here we have a single node
@@ -50,6 +52,16 @@ This is an example configuration for a Python project.
     # or we could have three nodes:
     #CELERYD_NODES="w1 w2 w3"
 
+    # Absolute or relative path to the 'celery' command:
+    CELERY_BIN="/usr/local/bin/celery"
+    #CELERY_BIN="/virtualenvs/def/bin/celery"
+
+    # App instance to use
+    # comment out this line if you don't use an app
+    CELERY_APP="proj"
+    # or fully qualified:
+    #CELERY_APP="proj.tasks:app"
+
     # Where to chdir at start.
     CELERYD_CHDIR="/opt/Myproject/"
 
@@ -72,7 +84,9 @@ This is an example configuration for a Python project.
 Example Django configuration
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-This is an example configuration for those using `django-celery`::
+This is an example configuration for those using `django-celery`:
+
+.. code-block:: bash
 
     # Name of nodes to start, here we have a single node
     CELERYD_NODES="w1"
@@ -82,18 +96,12 @@ This is an example configuration for those using `django-celery`::
     # Where to chdir at start.
     CELERYD_CHDIR="/opt/Myproject/"
 
-    # How to call "manage.py celeryd_multi"
-    CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
-
-    # How to call "manage.py celeryctl"
-    CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
+    # How to call "manage.py celery"
+    CELERY_BIN="$CELERYD_CHDIR/manage.py celery"
 
     # Extra arguments to celeryd
     CELERYD_OPTS="--time-limit=300 --concurrency=8"
 
-    # Name of the celery config module.
-    CELERY_CONFIG_MODULE="celeryconfig"
-
     # %n will be replaced with the nodename.
     CELERYD_LOG_FILE="/var/log/celery/%n.log"
     CELERYD_PID_FILE="/var/run/celery/%n.pid"
@@ -110,8 +118,10 @@ This is an example configuration for those using `django-celery`::
 Example Django configuration Using Virtualenv
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-In case you are using virtualenv, you should add the path to your 
-environment's python interpreter::
+In case you are using virtualenv, you should add the path to your
+environment's python interpreter:
+
+.. code-block:: bash
 
     # Name of nodes to start, here we have a single node
     CELERYD_NODES="w1"
@@ -120,16 +130,13 @@ environment's python interpreter::
 
     # Where to chdir at start.
     CELERYD_CHDIR="/opt/Myproject/"
-    
+
     # Python interpreter from environment.
     ENV_PYTHON="$CELERYD_CHDIR/env/bin/python"
-    
-    # How to call "manage.py celeryd_multi"
-    CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"
 
-    # How to call "manage.py celeryctl"
-    CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"
-    
+    # How to call "manage.py celery"
+    CELERY_BIN="$ENV_PYTHON $CELERYD_CHDIR/manage.py celery"
+
     # Extra arguments to celeryd
     CELERYD_OPTS="--time-limit=300 --concurrency=8"
 
@@ -152,6 +159,18 @@ environment's python interpreter::
 Available options
 ~~~~~~~~~~~~~~~~~~
 
+* CELERY_APP
+    App instance to use (value for ``--app`` argument).
+
+* CELERY_BIN
+    Absolute or relative path to the :program:`celery` program.
+    Examples:
+
+        * :file:`celery``
+        * :file:`/usr/local/bin/celery`
+        * :file:`/virtualenvs/proj/bin/celery`
+        * :file:`/virtualenvs/proj/bin/python -m celery`
+
 * CELERYD_NODES
     Node names to start.
 
@@ -171,20 +190,24 @@ Available options
 * CELERYD_LOG_LEVEL
     Log level to use for celeryd. Default is INFO.
 
-* CELERYD_MULTI
-    Path to the celeryd-multi program. Default is `celeryd-multi`.
-    You can point this to a virtualenv, or even use manage.py for django.
-
-* CELERYCTL
-    Path to the celeryctl program.  Default is `celeryctl`.
-    You can point this to a virtualenv, or even use manage.py for django.
-
 * CELERYD_USER
     User to run celeryd as. Default is current user.
 
 * CELERYD_GROUP
     Group to run celeryd as. Default is current user.
 
+* CELERY_CREATE_DIRS
+    Always create directories (log directory and pid file directory).
+    Default is to only create directories when no custom logfile/pidfile set.
+
+* CELERY_CREATE_RUNDIR
+    Always create pidfile directory.  By default only enabled when no custom
+    pidfile location set.
+
+* CELERY_CREATE_LOGDIR
+    Always create logfile directory.  By default only enable when no custom
+    logfile location set.
+
 .. _generic-initd-celerybeat:
 
 Init script: celerybeat
@@ -199,7 +222,19 @@ Example configuration
 
 This is an example configuration for a Python project:
 
-`/etc/default/celerybeat`::
+`/etc/default/celerybeat`:
+
+.. code-block:: bash
+
+    # Absolute or relative path to the 'celery' command:
+    CELERY_BIN="/usr/local/bin/celery"
+    #CELERY_BIN="/virtualenvs/def/bin/celery"
+
+    # App instance to use
+    # comment out this line if you don't use an app
+    CELERY_APP="proj"
+    # or fully qualified:
+    #CELERY_APP="proj.tasks:app"
 
     # Where to chdir at start.
     CELERYBEAT_CHDIR="/opt/Myproject/"
@@ -207,9 +242,6 @@ This is an example configuration for a Python project:
     # Extra arguments to celerybeat
     CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
 
-    # Name of the celery config module.#
-    CELERY_CONFIG_MODULE="celeryconfig"
-
 .. _generic-initd-celerybeat-django-example:
 
 Example Django configuration
@@ -225,8 +257,8 @@ This is an example configuration for those using `django-celery`
     # Name of the projects settings module.
     export DJANGO_SETTINGS_MODULE="settings"
 
-    # Path to celerybeat
-    CELERYBEAT="/opt/Project/manage.py celerybeat"
+    # Path to celery command
+    CELERY_BIN="/opt/Project/manage.py celery"
 
     # Extra arguments to celerybeat
     CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
@@ -236,6 +268,19 @@ This is an example configuration for those using `django-celery`
 Available options
 ~~~~~~~~~~~~~~~~~
 
+* CELERY_APP
+    App instance to use (value for ``--app`` argument).
+
+* CELERY_BIN
+    Absolute or relative path to the :program:`celery` program.
+    Examples:
+
+        * :file:`celery``
+        * :file:`/usr/local/bin/celery`
+        * :file:`/virtualenvs/proj/bin/celery`
+        * :file:`/virtualenvs/proj/bin/python -m celery`
+
+
 * CELERYBEAT_OPTS
     Additional arguments to celerybeat, see `celerybeat --help` for a
     list.
@@ -259,6 +304,18 @@ Available options
 * CELERYBEAT_GROUP
     Group to run celeryd as. Default is current user.
 
+* CELERY_CREATE_DIRS
+    Always create directories (log directory and pid file directory).
+    Default is to only create directories when no custom logfile/pidfile set.
+
+* CELERY_CREATE_RUNDIR
+    Always create pidfile directory.  By default only enabled when no custom
+    pidfile location set.
+
+* CELERY_CREATE_LOGDIR
+    Always create logfile directory.  By default only enable when no custom
+    logfile location set.
+
 .. _generic-initd-troubleshooting:
 
 Troubleshooting

+ 9 - 2
extra/generic-init.d/celerybeat

@@ -21,10 +21,11 @@
 # abnormally in the absence of a valid process ID.
 #set -e
 
+CELERY_BIN=${CELERY_BIN:-"celery"}
 DEFAULT_PID_FILE="/var/run/celery/beat.pid"
 DEFAULT_LOG_FILE="/var/log/celery/beat.log"
 DEFAULT_LOG_LEVEL="INFO"
-DEFAULT_CELERYBEAT="celery beat"
+DEFAULT_CELERYBEAT="$CELERY_BIN beat"
 
 # /etc/init.d/celerybeat: start and stop the celery periodic task scheduler daemon.
 
@@ -39,6 +40,12 @@ fi
 CELERYBEAT=${CELERYBEAT:-$DEFAULT_CELERYBEAT}
 CELERYBEAT_LOG_LEVEL=${CELERYBEAT_LOG_LEVEL:-${CELERYBEAT_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
 
+# Sets --app argument for CELERY_BIN
+CELERY_APP_ARG=""
+if [ ! -z "$CELERY_APP"]; then
+    CELERY_APP_ARG="--app=$CELERY_APP"
+fi
+
 # Set CELERY_CREATE_DIRS to always create log/pid dirs.
 CELERY_CREATE_DIRS=${CELERY_CREATE_DIRS:-0}
 CELERY_CREATE_RUNDIR=$CELERY_CREATE_DIRS
@@ -168,7 +175,7 @@ start_beat () {
     if [ -n "$VIRTUALENV" ]; then
         source $VIRTUALENV/bin/activate
     fi
-    $CELERYBEAT $CELERYBEAT_OPTS $DAEMON_OPTS --detach \
+    $CELERYBEAT $CELERY_APP_ARG $CELERYBEAT_OPTS $DAEMON_OPTS --detach \
                 --pidfile="$CELERYBEAT_PID_FILE"
 }
 

+ 16 - 3
extra/generic-init.d/celeryd

@@ -35,6 +35,13 @@ if [ -f "/etc/default/celeryd" ]; then
     . /etc/default/celeryd
 fi
 
+# Sets --app argument for CELERY_BIN
+CELERY_APP_ARG=""
+if [ ! -z "$CELERY_APP"]; then
+    CELERY_APP_ARG="--app=$CELERY_APP"
+fi
+
+
 # Set CELERY_CREATE_DIRS to always create log/pid dirs.
 CELERY_CREATE_DIRS=${CELERY_CREATE_DIRS:-0}
 CELERY_CREATE_RUNDIR=$CELERY_CREATE_DIRS
@@ -49,9 +56,10 @@ if [ -z "$CELERYD_LOG_FILE" ]; then
 fi
 
 CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
-CELERYD_MULTI=${CELERYD_MULTI:-"celery multi"}
+CELERY_BIN=${CELERY_BIN:-"celery"}
+CELERYD_MULTI=${CELERYD_MULTI:-"$CELERY_BIN multi"}
 CELERYD=${CELERYD:-$DEFAULT_CELERYD}
-CELERYCTL=${CELERYCTL:="celery"}
+CELERYCTL=${CELERYCTL:=$CELERY_BIN}
 CELERYD_NODES=${CELERYD_NODES:-$DEFAULT_NODES}
 
 export CELERY_LOADER
@@ -141,6 +149,7 @@ start_workers () {
                          --logfile="$CELERYD_LOG_FILE"      \
                          --loglevel="$CELERYD_LOG_LEVEL"    \
                          --cmd="$CELERYD"                   \
+                         $CELERY_APP_ARG                    \
                          $CELERYD_OPTS
 }
 
@@ -151,6 +160,7 @@ restart_workers () {
                            --logfile="$CELERYD_LOG_FILE"    \
                            --loglevel="$CELERYD_LOG_LEVEL"  \
                            --cmd="$CELERYD"                 \
+                           $CELERY_APP_ARG                  \
                            $CELERYD_OPTS
 }
 
@@ -174,7 +184,10 @@ case "$1" in
     ;;
 
     status)
-        $CELERYCTL status $CELERYCTL_OPTS
+        (
+            chdir "$CELERYD_CHDIR"
+            $CELERYCTL $CELERY_APP_ARG status $CELERYCTL_OPTS
+        )
     ;;
 
     restart)