daemonizing.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. .. _daemonizing:
  2. =============================
  3. Running celeryd as a daemon
  4. =============================
  5. Celery does not daemonize itself, please use one of the following
  6. daemonization tools.
  7. .. contents::
  8. :local:
  9. .. _daemon-generic:
  10. Generic init scripts
  11. ====================
  12. See the `contrib/generic-init.d/`_ directory Celery distribution.
  13. This directory contains generic bash init scripts for :program:`celeryd`,
  14. that should run on Linux, FreeBSD, OpenBSD, and other Unix platforms.
  15. .. _`contrib/generic-init.d/`:
  16. http://github.com/ask/celery/tree/master/contrib/generic-init.d/
  17. .. _generic-initd-celeryd:
  18. Init script: celeryd
  19. --------------------
  20. :Usage: `/etc/init.d/celeryd {start|stop|restart|status}`
  21. :Configuration file: /etc/default/celeryd
  22. To configure celeryd you probably need to at least tell it where to change
  23. directory to when it starts (to find your `celeryconfig`).
  24. .. _generic-initd-celeryd-example:
  25. Example configuration
  26. ~~~~~~~~~~~~~~~~~~~~~
  27. This is an example configuration for a Python project.
  28. :file:`/etc/default/celeryd`:
  29. # Name of nodes to start
  30. # here we have a single node
  31. CELERYD_NODES="w1"
  32. # or we could have three nodes:
  33. #CELERYD_NODES="w1 w2 w3"
  34. # Where to chdir at start.
  35. CELERYD_CHDIR="/opt/Myproject/"
  36. # Extra arguments to celeryd
  37. CELERYD_OPTS="--time-limit=300 --concurrency=8"
  38. # Name of the celery config module.
  39. CELERY_CONFIG_MODULE="celeryconfig"
  40. # %n will be replaced with the nodename.
  41. CELERYD_LOG_FILE="/var/log/celery/%n.log"
  42. CELERYD_PID_FILE="/var/run/celery/%n.pid"
  43. # Workers should run as an unprivileged user.
  44. CELERYD_USER="celery"
  45. CELERYD_GROUP="celery"
  46. .. _generic-initd-celeryd-django-example:
  47. Example Django configuration
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. This is an example configuration for those using `django-celery`::
  50. # Name of nodes to start, here we have a single node
  51. CELERYD_NODES="w1"
  52. # or we could have three nodes:
  53. #CELERYD_NODES="w1 w2 w3"
  54. # Where to chdir at start.
  55. CELERYD_CHDIR="/opt/Myproject/"
  56. # How to call "manage.py celeryd_multi"
  57. CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
  58. # Extra arguments to celeryd
  59. CELERYD_OPTS="--time-limit=300 --concurrency=8"
  60. # Name of the celery config module.
  61. CELERY_CONFIG_MODULE="celeryconfig"
  62. # %n will be replaced with the nodename.
  63. CELERYD_LOG_FILE="/var/log/celery/%n.log"
  64. CELERYD_PID_FILE="/var/run/celery/%n.pid"
  65. # Workers should run as an unprivileged user.
  66. CELERYD_USER="celery"
  67. CELERYD_GROUP="celery"
  68. # Name of the projects settings module.
  69. export DJANGO_SETTINGS_MODULE="settings"
  70. .. _generic-initd-celeryd-options:
  71. Available options
  72. ~~~~~~~~~~~~~~~~~~
  73. * CELERYD_NODES
  74. Node names to start.
  75. * CELERYD_OPTS
  76. Additional arguments to celeryd, see `celeryd --help` for a list.
  77. * CELERYD_CHDIR
  78. Path to change directory to at start. Default is to stay in the current
  79. directory.
  80. * CELERYD_PID_FILE
  81. Full path to the PID file. Default is /var/run/celeryd%n.pid
  82. * CELERYD_LOG_FILE
  83. Full path to the celeryd log file. Default is /var/log/celeryd@%n.log
  84. * CELERYD_LOG_LEVEL
  85. Log level to use for celeryd. Default is INFO.
  86. * CELERYD_MULTI
  87. Path to the celeryd-multi program. Default is `celeryd-multi`.
  88. You can point this to an virtualenv, or even use manage.py for django.
  89. * CELERYD_USER
  90. User to run celeryd as. Default is current user.
  91. * CELERYD_GROUP
  92. Group to run celeryd as. Default is current user.
  93. .. _generic-initd-celerybeat:
  94. Init script: celerybeat
  95. -----------------------
  96. :Usage: `/etc/init.d/celerybeat {start|stop|restart}`
  97. :Configuration file: /etc/default/celerybeat or /etc/default/celeryd
  98. .. _generic-initd-celerybeat-example:
  99. Example configuration
  100. ~~~~~~~~~~~~~~~~~~~~~
  101. This is an example configuration for a Python project:
  102. `/etc/default/celeryd`::
  103. # Where to chdir at start.
  104. CELERYD_CHDIR="/opt/Myproject/"
  105. # Extra arguments to celeryd
  106. CELERYD_OPTS="--time-limit=300"
  107. # Extra arguments to celerybeat
  108. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  109. # Name of the celery config module.#
  110. CELERY_CONFIG_MODULE="celeryconfig"
  111. .. _generic-initd-celerybeat-django-example:
  112. Example Django configuration
  113. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114. This is an example configuration for those using `django-celery`::
  115. # Where the Django project is.
  116. CELERYD_CHDIR="/opt/Project/"
  117. # Name of the projects settings module.
  118. export DJANGO_SETTINGS_MODULE="settings"
  119. # Path to celeryd
  120. CELERYD="/opt/Project/manage.py celeryd"
  121. # Path to celerybeat
  122. CELERYBEAT="/opt/Project/manage.py celerybeat"
  123. # Extra arguments to celerybeat
  124. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  125. .. _generic-initd-celerybeat-options:
  126. Available options
  127. ~~~~~~~~~~~~~~~~~
  128. * CELERYBEAT_OPTS
  129. Additional arguments to celerybeat, see `celerybeat --help` for a
  130. list.
  131. * CELERYBEAT_PIDFILE
  132. Full path to the PID file. Default is /var/run/celeryd.pid.
  133. * CELERYBEAT_LOGFILE
  134. Full path to the celeryd log file. Default is /var/log/celeryd.log
  135. * CELERYBEAT_LOG_LEVEL
  136. Log level to use for celeryd. Default is INFO.
  137. * CELERYBEAT
  138. Path to the celeryd program. Default is `celeryd`.
  139. You can point this to an virtualenv, or even use manage.py for django.
  140. * CELERYBEAT_USER
  141. User to run celeryd as. Default is current user.
  142. * CELERYBEAT_GROUP
  143. Group to run celeryd as. Default is current user.
  144. .. _generic-initd-troubleshooting:
  145. Troubleshooting
  146. ---------------
  147. If you can't get the init scripts to work, you should try running
  148. them in *verbose mode*::
  149. $ sh -x /etc/init.d/celeryd start
  150. This can reveal hints as to why the service won't start.
  151. Also you will see the commands generated, so you can try to run the celeryd
  152. command manually to read the resulting error output.
  153. For example my `sh -x` output does this::
  154. ++ start-stop-daemon --start --chdir /opt/Opal/release/opal --quiet \
  155. --oknodo --background --make-pidfile --pidfile /var/run/celeryd.pid \
  156. --exec /opt/Opal/release/opal/manage.py celeryd -- --time-limit=300 \
  157. -f /var/log/celeryd.log -l INFO
  158. Run the celeryd command after `--exec` (without the `--`) to show the
  159. actual resulting output::
  160. $ /opt/Opal/release/opal/manage.py celeryd --time-limit=300 \
  161. -f /var/log/celeryd.log -l INFO
  162. .. _daemon-supervisord:
  163. `supervisord`_
  164. ==============
  165. * `contrib/supervisord/`_
  166. .. _`contrib/supervisord/`:
  167. http://github.com/ask/celery/tree/master/contrib/supervisord/
  168. .. _`supervisord`: http://supervisord.org/
  169. .. _daemon-launchd:
  170. launchd (OS X)
  171. ==============
  172. * `contrib/mac/`_
  173. .. _`contrib/mac/`:
  174. http://github.com/ask/celery/tree/master/contrib/mac/
  175. .. _daemon-windows:
  176. Windows
  177. =======
  178. See this excellent external tutorial:
  179. http://www.calazan.com/windows-tip-run-applications-in-the-background-using-task-scheduler/