daemonizing.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. start-stop-daemon (Debian/Ubuntu/++)
  94. ====================================
  95. See the `contrib/debian/init.d/`_ directory in the Celery distribution, this
  96. directory contains init scripts for celeryd and celerybeat.
  97. These scripts are configured in :file:`/etc/default/celeryd`.
  98. .. _`contrib/debian/init.d/`:
  99. http://github.com/ask/celery/tree/master/contrib/debian/
  100. .. _debian-initd-celeryd:
  101. Init script: celeryd
  102. --------------------
  103. :Usage: `/etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status}`
  104. :Configuration file: /etc/default/celeryd
  105. To configure celeryd you probably need to at least tell it where to change
  106. directory to when it starts (to find your `celeryconfig`).
  107. .. _debian-initd-celeryd-example:
  108. Example configuration
  109. ~~~~~~~~~~~~~~~~~~~~~
  110. This is an example configuration for a Python project.
  111. :file:`/etc/default/celeryd`:
  112. # Where to chdir at start.
  113. CELERYD_CHDIR="/opt/Myproject/"
  114. # Extra arguments to celeryd
  115. CELERYD_OPTS="--time-limit=300"
  116. # Name of the celery config module.#
  117. CELERY_CONFIG_MODULE="celeryconfig"
  118. .. _debian-initd-celeryd-django-example:
  119. Example Django configuration
  120. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. This is an example configuration for those using `django-celery`::
  122. # Where the Django project is.
  123. CELERYD_CHDIR="/opt/Project/"
  124. # Path to celeryd
  125. CELERYD="/opt/Project/manage.py celeryd"
  126. # Name of the projects settings module.
  127. export DJANGO_SETTINGS_MODULE="settings"
  128. .. _debian-initd-celeryd-options:
  129. Available options
  130. ~~~~~~~~~~~~~~~~~~
  131. * CELERYD_OPTS
  132. Additional arguments to celeryd, see `celeryd --help` for a list.
  133. * CELERYD_CHDIR
  134. Path to change directory to at start. Default is to stay in the current
  135. directory.
  136. * CELERYD_PID_FILE
  137. Full path to the PID file. Default is /var/run/celeryd.pid.
  138. * CELERYD_LOG_FILE
  139. Full path to the celeryd log file. Default is /var/log/celeryd.log
  140. * CELERYD_LOG_LEVEL
  141. Log level to use for celeryd. Default is INFO.
  142. * CELERYD
  143. Path to the celeryd program. Default is `celeryd`.
  144. You can point this to an virtualenv, or even use manage.py for django.
  145. * CELERYD_USER
  146. User to run celeryd as. Default is current user.
  147. * CELERYD_GROUP
  148. Group to run celeryd as. Default is current user.
  149. .. _debian-initd-celerybeat:
  150. Init script: celerybeat
  151. -----------------------
  152. :Usage: `/etc/init.d/celerybeat {start|stop|force-reload|restart|try-restart|status}`
  153. :Configuration file: /etc/default/celerybeat or /etc/default/celeryd
  154. .. _debian-initd-celerybeat-example:
  155. Example configuration
  156. ~~~~~~~~~~~~~~~~~~~~~
  157. This is an example configuration for a Python project:
  158. `/etc/default/celeryd`::
  159. # Where to chdir at start.
  160. CELERYD_CHDIR="/opt/Myproject/"
  161. # Extra arguments to celeryd
  162. CELERYD_OPTS="--time-limit=300"
  163. # Extra arguments to celerybeat
  164. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  165. # Name of the celery config module.#
  166. CELERY_CONFIG_MODULE="celeryconfig"
  167. .. _debian-initd-celerybeat-django-example:
  168. Example Django configuration
  169. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170. This is an example configuration for those using `django-celery`::
  171. # Where the Django project is.
  172. CELERYD_CHDIR="/opt/Project/"
  173. # Name of the projects settings module.
  174. export DJANGO_SETTINGS_MODULE="settings"
  175. # Path to celeryd
  176. CELERYD="/opt/Project/manage.py celeryd"
  177. # Path to celerybeat
  178. CELERYBEAT="/opt/Project/manage.py celerybeat"
  179. # Extra arguments to celerybeat
  180. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  181. .. _debian-initd-celerybeat-options:
  182. Available options
  183. ~~~~~~~~~~~~~~~~~
  184. * CELERYBEAT_OPTS
  185. Additional arguments to celerybeat, see `celerybeat --help` for a
  186. list.
  187. * CELERYBEAT_PIDFILE
  188. Full path to the PID file. Default is /var/run/celeryd.pid.
  189. * CELERYBEAT_LOGFILE
  190. Full path to the celeryd log file. Default is /var/log/celeryd.log
  191. * CELERYBEAT_LOG_LEVEL
  192. Log level to use for celeryd. Default is INFO.
  193. * CELERYBEAT
  194. Path to the celeryd program. Default is `celeryd`.
  195. You can point this to an virtualenv, or even use manage.py for django.
  196. * CELERYBEAT_USER
  197. User to run celeryd as. Default is current user.
  198. * CELERYBEAT_GROUP
  199. Group to run celeryd as. Default is current user.
  200. .. _debian-initd-troubleshooting:
  201. Troubleshooting
  202. ---------------
  203. If you can't get the init scripts to work, you should try running
  204. them in *verbose mode*::
  205. $ sh -x /etc/init.d/celeryd start
  206. This can reveal hints as to why the service won't start.
  207. Also you will see the commands generated, so you can try to run the celeryd
  208. command manually to read the resulting error output.
  209. For example my `sh -x` output does this::
  210. ++ start-stop-daemon --start --chdir /opt/Opal/release/opal --quiet \
  211. --oknodo --background --make-pidfile --pidfile /var/run/celeryd.pid \
  212. --exec /opt/Opal/release/opal/manage.py celeryd -- --time-limit=300 \
  213. -f /var/log/celeryd.log -l INFO
  214. Run the celeryd command after `--exec` (without the `--`) to show the
  215. actual resulting output::
  216. $ /opt/Opal/release/opal/manage.py celeryd --time-limit=300 \
  217. -f /var/log/celeryd.log -l INFO
  218. .. _daemon-supervisord:
  219. `supervisord`_
  220. ==============
  221. * `contrib/supervisord/`_
  222. .. _`contrib/supervisord/`:
  223. http://github.com/ask/celery/tree/master/contrib/supervisord/
  224. .. _`supervisord`: http://supervisord.org/
  225. .. _daemon-launchd:
  226. launchd (OS X)
  227. ==============
  228. * `contrib/mac/`_
  229. .. _`contrib/mac/`:
  230. http://github.com/ask/celery/tree/master/contrib/mac/