Просмотр исходного кода

[deployment][generic-init.d] Adds the ability to set `su` options. Closes #3055

This adds the following configuration options that can be
modified in ``/etc/init.d/celeryd``/``/etc/init.d/celerybeat``.

- ``CELERYD_SU``

    path to su utility.

- ``CELERYD_SU_OPTIONS``

    arguments to su.

- ``CELERYBEAT_SU``

- ``CELERYBEAT_SU_OPTIONS``
Ask Solem 9 лет назад
Родитель
Сommit
040a315b60
3 измененных файлов с 25 добавлено и 2 удалено
  1. 13 0
      docs/tutorials/daemonizing.rst
  2. 5 1
      extra/generic-init.d/celerybeat
  3. 7 1
      extra/generic-init.d/celeryd

+ 13 - 0
docs/tutorials/daemonizing.rst

@@ -119,6 +119,19 @@ This is an example configuration for a Python project.
     # and owned by the userid/group configured.
     CELERY_CREATE_DIRS=1
 
+Using a login shell
+~~~~~~~~~~~~~~~~~~~
+
+You can inherit the environment of the ``CELERYD_USER`` by using a login
+shell:
+
+.. code-block:: bash
+
+    CELERYD_SU_OPTIONS="-l"
+
+Note that this is not recommended, and that you should only use this option
+when absolutely necessary.
+
 .. _generic-initd-celeryd-django-example:
 
 Example Django configuration

+ 5 - 1
extra/generic-init.d/celerybeat

@@ -110,6 +110,9 @@ DEFAULT_CELERYBEAT="$CELERY_BIN beat"
 CELERYBEAT=${CELERYBEAT:-$DEFAULT_CELERYBEAT}
 CELERYBEAT_LOG_LEVEL=${CELERYBEAT_LOG_LEVEL:-${CELERYBEAT_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
 
+CELERYBEAT_SU=${CELERYBEAT_SU:-"su"}
+CELERYBEAT_SU_ARGS=${CELERYBEAT_SU_ARGS:-""}
+
 # Sets --app argument for CELERY_BIN
 CELERY_APP_ARG=""
 if [ ! -z "$CELERY_APP" ]; then
@@ -240,7 +243,8 @@ stop_beat () {
 }
 
 _chuid () {
-    su "$CELERYBEAT_USER" -c "$CELERYBEAT $*"
+    ${CELERYBEAT_SU} ${CELERYBEAT_SU_ARGS} \
+        "$CELERYBEAT_USER" -c "$CELERYBEAT $*"
 }
 
 start_beat () {

+ 7 - 1
extra/generic-init.d/celeryd

@@ -115,6 +115,12 @@ if [ ! -z "$CELERY_APP" ]; then
     CELERY_APP_ARG="--app=$CELERY_APP"
 fi
 
+# Options to su
+# can be used to enable login shell (CELERYD_SU_ARGS="-l"),
+# or even to use start-stop-daemon instead of su.
+CELERYD_SU=${CELERY_SU:-"su"}
+CELERYD_SU_ARGS=${CELERYD_SU_ARGS:-""}
+
 CELERYD_USER=${CELERYD_USER:-$DEFAULT_USER}
 
 # Set CELERY_CREATE_DIRS to always create log/pid dirs.
@@ -235,7 +241,7 @@ _get_pids() {
 
 
 _chuid () {
-    su "$CELERYD_USER" -c "$CELERYD_MULTI $*"
+    ${CELERYD_SU} ${CELERYD_SU_ARGS} "$CELERYD_USER" -c "$CELERYD_MULTI $*"
 }