daemonizing.rst 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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/celerybeat`::
  103. # Where to chdir at start.
  104. CELERYBEAT_CHDIR="/opt/Myproject/"
  105. # Extra arguments to celerybeat
  106. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  107. # Name of the celery config module.#
  108. CELERY_CONFIG_MODULE="celeryconfig"
  109. .. _generic-initd-celerybeat-django-example:
  110. Example Django configuration
  111. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112. This is an example configuration for those using `django-celery`
  113. `/etc/default/celerybeat`::
  114. # Where the Django project is.
  115. CELERYBEAT_CHDIR="/opt/Project/"
  116. # Name of the projects settings module.
  117. export DJANGO_SETTINGS_MODULE="settings"
  118. # Path to celerybeat
  119. CELERYBEAT="/opt/Project/manage.py celerybeat"
  120. # Extra arguments to celerybeat
  121. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  122. .. _generic-initd-celerybeat-options:
  123. Available options
  124. ~~~~~~~~~~~~~~~~~
  125. * CELERYBEAT_OPTS
  126. Additional arguments to celerybeat, see `celerybeat --help` for a
  127. list.
  128. * CELERYBEAT_PIDFILE
  129. Full path to the PID file. Default is /var/run/celeryd.pid.
  130. * CELERYBEAT_LOGFILE
  131. Full path to the celeryd log file. Default is /var/log/celeryd.log
  132. * CELERYBEAT_LOG_LEVEL
  133. Log level to use for celeryd. Default is INFO.
  134. * CELERYBEAT
  135. Path to the celeryd program. Default is `celeryd`.
  136. You can point this to an virtualenv, or even use manage.py for django.
  137. * CELERYBEAT_USER
  138. User to run celeryd as. Default is current user.
  139. * CELERYBEAT_GROUP
  140. Group to run celeryd as. Default is current user.
  141. .. _generic-initd-troubleshooting:
  142. Troubleshooting
  143. ---------------
  144. If you can't get the init scripts to work, you should try running
  145. them in *verbose mode*::
  146. $ sh -x /etc/init.d/celeryd start
  147. This can reveal hints as to why the service won't start.
  148. Also you will see the commands generated, so you can try to run the celeryd
  149. command manually to read the resulting error output.
  150. For example my `sh -x` output does this::
  151. ++ start-stop-daemon --start --chdir /opt/Opal/release/opal --quiet \
  152. --oknodo --background --make-pidfile --pidfile /var/run/celeryd.pid \
  153. --exec /opt/Opal/release/opal/manage.py celeryd -- --time-limit=300 \
  154. -f /var/log/celeryd.log -l INFO
  155. Run the celeryd command after `--exec` (without the `--`) to show the
  156. actual resulting output::
  157. $ /opt/Opal/release/opal/manage.py celeryd --time-limit=300 \
  158. -f /var/log/celeryd.log -l INFO
  159. .. _daemon-supervisord:
  160. `supervisord`_
  161. ==============
  162. * `contrib/supervisord/`_
  163. .. _`contrib/supervisord/`:
  164. http://github.com/ask/celery/tree/master/contrib/supervisord/
  165. .. _`supervisord`: http://supervisord.org/
  166. .. _daemon-launchd:
  167. launchd (OS X)
  168. ==============
  169. * `contrib/mac/`_
  170. .. _`contrib/mac/`:
  171. http://github.com/ask/celery/tree/master/contrib/mac/
  172. .. _daemon-windows:
  173. Windows
  174. =======
  175. See this excellent external tutorial:
  176. http://www.calazan.com/windows-tip-run-applications-in-the-background-using-task-scheduler/