Jelajahi Sumber

Edit tutorial for demonizing

Anarchist666 12 tahun lalu
induk
melakukan
964311d595
3 mengubah file dengan 54 tambahan dan 18 penghapusan
  1. 39 0
      docs/tutorials/daemonizing.rst
  2. 10 14
      extra/systemd/celery
  3. 5 4
      extra/systemd/celery.service

+ 39 - 0
docs/tutorials/daemonizing.rst

@@ -309,6 +309,45 @@ Available options
     Always create logfile directory.  By default only enable when no custom
     logfile location set.
 
+.. _generic-systemd-celery:
+
+Service file: celery.service
+----------------------------
+:Configuration file: /etc/conf.d/celery
+:Usage: `systemctl {start|stop|restart|status} celery.service`
+
+To create a temporary folder for the log and pid files change user and group in 
+/usr/lib/tmpfiles.d/celery.conf.
+Setting WorkingDirectory in /usr/lib/systemd/system/celery.service defines chdir.
+
+.. _generic-systemd-celery-example:
+
+Example configuration
+~~~~~~~~~~~~~~~~~~~~~
+
+This is an example configuration for a Python project:
+
+:file:`/etc/conf.d/celery`:
+
+.. code-block:: bash
+
+    # Name of nodes to start
+    # here we have a single node
+    CELERYD_NODES="w1"
+    # 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"
+
+    # Extra command-line arguments to the worker
+    CELERYD_OPTS="--time-limit=300 --concurrency=8"
+
+    # %N will be replaced with the first part of the nodename.
+    CELERYD_LOG_FILE="/var/log/celery/%N.log"
+    CELERYD_PID_FILE="/var/run/celery/%N.pid"
+
 .. _generic-initd-troubleshooting:
 
 Troubleshooting

+ 10 - 14
extra/systemd/celery

@@ -1,20 +1,16 @@
-# Name of nodes to start, here we have a single node
+# Name of nodes to start
+# here we have a single node
 CELERYD_NODES="w1"
 # or we could have three nodes:
 #CELERYD_NODES="w1 w2 w3"
 
-# Where to chdir at start.
-#CELERYD_CHDIR="/opt/Myproject/"
+# Absolute or relative path to the 'celery' command:
+CELERY_BIN="/usr/local/bin/celery"
+#CELERY_BIN="/virtualenvs/def/bin/celery"
 
-# How to call "manage.py celeryd_multi"
-CELERYD_MULTI="celeryd_multi"
+# Extra command-line arguments to the worker
+CELERYD_OPTS="--time-limit=300 --concurrency=8"
 
-# Extra arguments to celeryd
-CELERYD_OPTS="--time-limit=300 --concurrency=3"
-
-# %n will be replaced with the nodename.
-CELERYD_LOG_FILE="/var/log/celery/%n.log"
-CELERYD_PID_FILE="/var/run/celery/%n.pid"
-
-#Logging level, choose between `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`, or `FATAL`.
-CELERYD_LOG_LEVEL="INFO"
+# %N will be replaced with the first part of the nodename.
+CELERYD_LOG_FILE="/var/log/celery/%N.log"
+CELERYD_PID_FILE="/var/run/celery/%N.pid"

+ 5 - 4
extra/systemd/celery.service

@@ -4,12 +4,13 @@ After=network.target
 
 [Service]
 Type=forking
-User=user
+User=anarchist
 Group=users
 EnvironmentFile=-/etc/conf.d/celery
-ExecStart=/usr/bin/python2 ${CELERYD_CHDIR}/manage.py ${CELERYD_MULTI} start $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} $CELERYD_OPTS 
-ExecStop=/usr/bin/python2 ${CELERYD_CHDIR}/manage.py ${CELERYD_MULTI} stopwait $CELERYD_NODES --pidfile=${CELERYD_PID_FILE}
-ExecReload=/usr/bin/python2 ${CELERYD_CHDIR}/manage.py ${CELERYD_MULTI} restart $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} $CELERYD_OPTS 
+WorkingDirectory=/opt/Myproject/
+ExecStart=/usr/bin/python2 ${CELERYD_BIN}/manage.py multi start $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel="INFO" $CELERYD_OPTS 
+ExecStop=/usr/bin/python2 ${CELERYD_BIN}/manage.py multi stopwait $CELERYD_NODES --pidfile=${CELERYD_PID_FILE}
+ExecReload=/usr/bin/python2 ${CELERYD_BIN}/manage.py multi restart $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel="INFO" $CELERYD_OPTS 
 
 [Install]
 WantedBy=multi-user.target