| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 | .. _daemonizing:================================ Running the worker as a daemon================================Celery does not daemonize itself, please use one of the followingdaemonization tools... contents::    :local:.. _daemon-generic:Generic init scripts====================See the `extra/generic-init.d/`_ directory Celery distribution.This directory contains generic bash init scripts for the:program:`celery worker` program,these should run on Linux, FreeBSD, OpenBSD, and other Unix-like platforms... _`extra/generic-init.d/`:    https://github.com/celery/celery/tree/3.1/extra/generic-init.d/.. _generic-initd-celeryd:Init script: celeryd--------------------:Usage: `/etc/init.d/celeryd {start|stop|restart|status}`:Configuration file: :file:`/etc/default/celeryd`To configure this script to run the worker properly you probably need to at leasttell it where to changedirectory to when it starts (to find the module containing your app, or yourconfiguration module).The daemonization script is configured by the file ``/etc/default/celeryd``,which is a shell (sh) script.  You can add environment variables and theconfiguration options below to this file.  To add environment variables youmust also export them (e.g. ``export DISPLAY=":0"``).. Admonition:: Superuser privileges required    The init scripts can only be used by root,    and the shell configuration file must also be owned by root.    Unprivileged users do not need to use the init script,    instead they can use the :program:`celery multi` utility (or    :program:`celery worker --detach`):    .. code-block:: console        $ celery multi start worker1 \            -A proj \            --pidfile="$HOME/run/celery/%n.pid" \            --logfile="$HOME/log/celery/%n%I.log"        $ celery multi restart worker1 \            -A proj \            --logfile="$HOME/log/celery/%n%I.log" \            --pidfile="$HOME/run/celery/%n.pid        $ celery multi stopwait worker1 --pidfile="$HOME/run/celery/%n.pid".. _generic-initd-celeryd-example:Example configuration~~~~~~~~~~~~~~~~~~~~~This is an example configuration for a Python project.:file:`/etc/default/celeryd`:.. code-block:: bash    # Names of nodes to start    #   most people will only start one node:    CELERYD_NODES="worker1"    #   but you can also start multiple and configure settings    #   for each in CELERYD_OPTS (see `celery multi --help` for examples):    #CELERYD_NODES="worker1 worker2 worker3"    #   alternatively, you can specify the number of nodes to start:    #CELERYD_NODES=10    # 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/"    # Extra command-line arguments to the worker    CELERYD_OPTS="--time-limit=300 --concurrency=8"    # Set logging level to DEBUG    #CELERYD_LOG_LEVEL="DEBUG"    # %n will be replaced with the first part of the nodename.    CELERYD_LOG_FILE="/var/log/celery/%n%I.log"    CELERYD_PID_FILE="/var/run/celery/%n.pid"    # Workers should run as an unprivileged user.    #   You need to create this user manually (or you can choose    #   a user/group combination that already exists, e.g. nobody).    CELERYD_USER="celery"    CELERYD_GROUP="celery"    # If enabled pid and log directories will be created if missing,    # and owned by the userid/group configured.    CELERY_CREATE_DIRS=1Using a login shell~~~~~~~~~~~~~~~~~~~You can inherit the environment of the ``CELERYD_USER`` by using a loginshell:.. code-block:: bash    CELERYD_SU_ARGS="-l"Note that this is not recommended, and that you should only use this optionwhen absolutely necessary... _generic-initd-celeryd-django-example:Example Django configuration~~~~~~~~~~~~~~~~~~~~~~~~~~~~Django users now uses the exact same template as above,but make sure that the module that defines your Celery app instancealso sets a default value for :envvar:`DJANGO_SETTINGS_MODULE`as shown in the example Django project in :ref:`django-first-steps`... _generic-initd-celeryd-options:Available options~~~~~~~~~~~~~~~~~~* ``CELERY_APP``    App instance to use (value for :option:`--app <celery --app>` argument).    If you're still using the old API, or :pypi:`django-celery`, then you    can omit this setting.* ``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``    List of node names to start (separated by space).* ``CELERYD_OPTS``    Additional command-line arguments for the worker, see    `celery worker --help` for a list.  This also supports the extended    syntax used by `multi` to configure settings for individual nodes.    See `celery multi --help` for some multi-node configuration examples.* ``CELERYD_CHDIR``    Path to change directory to at start. Default is to stay in the current    directory.* ``CELERYD_PID_FILE``    Full path to the PID file. Default is /var/run/celery/%n.pid* ``CELERYD_LOG_FILE``    Full path to the worker log file. Default is /var/log/celery/%n%I.log    **Note**: Using `%I` is important when using the prefork pool as having    multiple processes share the same log file will lead to race conditions.* ``CELERYD_LOG_LEVEL``    Worker log level. Default is INFO.* ``CELERYD_USER``    User to run the worker as. Default is current user.* ``CELERYD_GROUP``    Group to run worker 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-----------------------:Usage: `/etc/init.d/celerybeat {start|stop|restart}`:Configuration file: :file:`/etc/default/celerybeat` or                     :file:``/etc/default/celeryd`... _generic-initd-celerybeat-example:Example configuration~~~~~~~~~~~~~~~~~~~~~This is an example configuration for a Python project:`/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/"    # Extra arguments to celerybeat    CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule".. _generic-initd-celerybeat-django-example:Example Django configuration~~~~~~~~~~~~~~~~~~~~~~~~~~~~You should use the same template as above, but make sure the``DJANGO_SETTINGS_MODULE`` variable is set (and exported), and that``CELERYD_CHDIR`` is set to the projects directory:.. code-block:: bash    export DJANGO_SETTINGS_MODULE="settings"    CELERYD_CHDIR="/opt/MyProject".. _generic-initd-celerybeat-options:Available options~~~~~~~~~~~~~~~~~* ``CELERY_APP``    App instance to use (value for :option:`--app <celery --app>` argument).* ``CELERYBEAT_OPTS``    Additional arguments to celerybeat, see `celerybeat --help` for a    list.* ``CELERYBEAT_PID_FILE``    Full path to the PID file. Default is /var/run/celeryd.pid.* ``CELERYBEAT_LOG_FILE``    Full path to the celeryd log file. Default is /var/log/celeryd.log* ``CELERYBEAT_LOG_LEVEL``    Log level to use for celeryd. Default is INFO.* ``CELERYBEAT_USER``    User to run beat as. Default is current user.* ``CELERYBEAT_GROUP``    Group to run beat 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... _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/celeryTo create a temporary folders for the log and pid files change user and group in:file:`/usr/lib/tmpfiles.d/celery.conf`.To configure user, group, ``chdir`` change settings:User, Group and WorkingDirectory defines in:file:`/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.    # - %I will be replaced with the current child process index    #   and is important when using the prefork pool to avoid race conditions.    CELERYD_LOG_FILE="/var/log/celery/%n%I.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 :pypi:`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.    # - %I will be replaced with the current child process index    CELERYD_LOG_FILE="/var/log/celery/%n%I.log"    CELERYD_PID_FILE="/var/run/celery/%n.pid"To add an environment variable such as DJANGO_SETTINGS_MODULE use theEnvironment in celery.service... _generic-initd-troubleshooting:Troubleshooting---------------If you can't get the init scripts to work, you should try runningthem in *verbose mode*:.. code-block:: console    # sh -x /etc/init.d/celeryd startThis can reveal hints as to why the service won't start.If the worker starts with "OK" but exits almost immediately afterwardsand there is nothing in the log file, then there is probably an errorbut as the daemons standard outputs are already closed you'llnot be able to see them anywhere.  For this situation you can usethe :envvar:`C_FAKEFORK` environment variable to skip thedaemonization step:.. code-block:: console    # C_FAKEFORK=1 sh -x /etc/init.d/celeryd startand now you should be able to see the errors.Commonly such errors are caused by insufficient permissionsto read from, or write to a file, and also by syntax errorsin configuration modules, user modules, 3rd party libraries,or even from Celery itself (if you've found a bug, in which caseyou should :ref:`report it <reporting-bugs>`)... _daemon-supervisord::pypi:`supervisor`==================* `extra/supervisord/`_.. _`extra/supervisord/`:    https://github.com/celery/celery/tree/3.1/extra/supervisord/.. _daemon-launchd:``launchd`` (OS X)==================* `extra/osx`_.. _`extra/osx`:    https://github.com/celery/celery/tree/3.1/extra/osx/.. _daemon-windows:Windows=======See this excellent external tutorial:http://www.calazan.com/windows-tip-run-applications-in-the-background-using-task-scheduler/
 |