Sfoglia il codice sorgente

Merge branch 'Anarchist666/master'

Ask Solem 11 anni fa
parent
commit
16ba099e44
3 ha cambiato i file con 99 aggiunte e 0 eliminazioni
  1. 80 0
      docs/tutorials/daemonizing.rst
  2. 2 0
      extra/systemd/celery.conf
  3. 17 0
      extra/systemd/celery.service

+ 80 - 0
docs/tutorials/daemonizing.rst

@@ -246,6 +246,86 @@ Available options
 * CELERY_CREATE_LOGDIR
     Always create logfile directory.  By default only enable when no custom
     logfile location set.
+    
+.. _daemon-systemd-generic:
+
+Usage systemd
+=============
+
+.. _generic-systemd-celery:
+
+Service file: celery.service
+----------------------------
+
+:Usage: `systemctl {start|stop|restart|status} celery.service`
+:Configuration file: /etc/conf.d/celery
+
+To create a temporary folders for the log and pid files change user and group in 
+/usr/lib/tmpfiles.d/celery.conf.
+To configure user, group, chdir change settings User, Group and WorkingDirectory defines 
+in /usr/lib/systemd/system/celery.service. 
+
+.. _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"
+    
+    # How to call manage.py
+    CELERYD_MULTI="multi"
+
+    # 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-systemd-celeryd-django-example:
+
+Example Django configuration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+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"
+    # or we could have three nodes:
+    #CELERYD_NODES="w1 w2 w3"
+
+    # Absolute path to "manage.py"
+    CELERY_BIN="/opt/Myproject/manage.py"
+    
+    # How to call manage.py
+    CELERYD_MULTI="celery multi"
+
+    # 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"
+
+To add an environment variable such as DJANGO_SETTINGS_MODULE use the 
+Environment in celery.service.
 
 .. _generic-initd-troubleshooting:
 

+ 2 - 0
extra/systemd/celery.conf

@@ -0,0 +1,2 @@
+d /run/celery 0755 user users -
+d /var/log/celery 0755 user users -

+ 17 - 0
extra/systemd/celery.service

@@ -0,0 +1,17 @@
+[Unit]
+Description=Celery Nodes Daemon
+After=network.target
+
+[Service]
+Type=forking
+User=user
+Group=users
+#Environment=DJANGO_SETTINGS_MODULE=MyProject.settings
+EnvironmentFile=-/etc/conf.d/celery
+WorkingDirectory=/opt/Myproject/
+ExecStart=/usr/bin/python2 ${CELERY_BIN} $CELERYD_MULTI start $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel="INFO" $CELERYD_OPTS
+ExecStop=/usr/bin/python2 ${CELERY_BIN} $CELERYD_MULTI stopwait $CELERYD_NODES --pidfile=${CELERYD_PID_FILE}
+ExecReload=/usr/bin/python2 ${CELERY_BIN} $CELERYD_MULTI restart $CELERYD_NODES --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel="INFO" $CELERYD_OPTS
+
+[Install]
+WantedBy=multi-user.target