daemonizing.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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/celery/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. # How to call "manage.py celeryctl"
  59. CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
  60. # Extra arguments to celeryd
  61. CELERYD_OPTS="--time-limit=300 --concurrency=8"
  62. # Name of the celery config module.
  63. CELERY_CONFIG_MODULE="celeryconfig"
  64. # %n will be replaced with the nodename.
  65. CELERYD_LOG_FILE="/var/log/celery/%n.log"
  66. CELERYD_PID_FILE="/var/run/celery/%n.pid"
  67. # Workers should run as an unprivileged user.
  68. CELERYD_USER="celery"
  69. CELERYD_GROUP="celery"
  70. # Name of the projects settings module.
  71. export DJANGO_SETTINGS_MODULE="settings"
  72. .. _generic-initd-celeryd-django-with-env-example:
  73. Example Django configuration Using Virtualenv
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. In case you are using virtualenv, you should add the path to your
  76. environment's python interpreter::
  77. # Name of nodes to start, here we have a single node
  78. CELERYD_NODES="w1"
  79. # or we could have three nodes:
  80. #CELERYD_NODES="w1 w2 w3"
  81. # Where to chdir at start.
  82. CELERYD_CHDIR="/opt/Myproject/"
  83. # Python interpreter from environment.
  84. ENV_PYTHON="$CELERYD_CHDIR/env/bin/python"
  85. # How to call "manage.py celeryd_multi"
  86. CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"
  87. # How to call "manage.py celeryctl"
  88. CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"
  89. # Extra arguments to celeryd
  90. CELERYD_OPTS="--time-limit=300 --concurrency=8"
  91. # Name of the celery config module.
  92. CELERY_CONFIG_MODULE="celeryconfig"
  93. # %n will be replaced with the nodename.
  94. CELERYD_LOG_FILE="/var/log/celery/%n.log"
  95. CELERYD_PID_FILE="/var/run/celery/%n.pid"
  96. # Workers should run as an unprivileged user.
  97. CELERYD_USER="celery"
  98. CELERYD_GROUP="celery"
  99. # Name of the projects settings module.
  100. export DJANGO_SETTINGS_MODULE="settings"
  101. .. _generic-initd-celeryd-options:
  102. Available options
  103. ~~~~~~~~~~~~~~~~~~
  104. * CELERYD_NODES
  105. Node names to start.
  106. * CELERYD_OPTS
  107. Additional arguments to celeryd, see `celeryd --help` for a list.
  108. * CELERYD_CHDIR
  109. Path to change directory to at start. Default is to stay in the current
  110. directory.
  111. * CELERYD_PID_FILE
  112. Full path to the PID file. Default is /var/run/celeryd%n.pid
  113. * CELERYD_LOG_FILE
  114. Full path to the celeryd log file. Default is /var/log/celeryd@%n.log
  115. * CELERYD_LOG_LEVEL
  116. Log level to use for celeryd. Default is INFO.
  117. * CELERYD_MULTI
  118. Path to the celeryd-multi program. Default is `celeryd-multi`.
  119. You can point this to a virtualenv, or even use manage.py for django.
  120. * CELERYCTL
  121. Path to the celeryctl program. Default is `celeryctl`.
  122. You can point this to a virtualenv, or even use manage.py for django.
  123. * CELERYD_USER
  124. User to run celeryd as. Default is current user.
  125. * CELERYD_GROUP
  126. Group to run celeryd as. Default is current user.
  127. .. _generic-initd-celerybeat:
  128. Init script: celerybeat
  129. -----------------------
  130. :Usage: `/etc/init.d/celerybeat {start|stop|restart}`
  131. :Configuration file: /etc/default/celerybeat or /etc/default/celeryd
  132. .. _generic-initd-celerybeat-example:
  133. Example configuration
  134. ~~~~~~~~~~~~~~~~~~~~~
  135. This is an example configuration for a Python project:
  136. `/etc/default/celerybeat`::
  137. # Where to chdir at start.
  138. CELERYBEAT_CHDIR="/opt/Myproject/"
  139. # Extra arguments to celerybeat
  140. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  141. # Name of the celery config module.#
  142. CELERY_CONFIG_MODULE="celeryconfig"
  143. .. _generic-initd-celerybeat-django-example:
  144. Example Django configuration
  145. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146. This is an example configuration for those using `django-celery`
  147. `/etc/default/celerybeat`::
  148. # Where the Django project is.
  149. CELERYBEAT_CHDIR="/opt/Project/"
  150. # Name of the projects settings module.
  151. export DJANGO_SETTINGS_MODULE="settings"
  152. # Path to celerybeat
  153. CELERYBEAT="/opt/Project/manage.py celerybeat"
  154. # Extra arguments to celerybeat
  155. CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
  156. .. _generic-initd-celerybeat-options:
  157. Available options
  158. ~~~~~~~~~~~~~~~~~
  159. * CELERYBEAT_OPTS
  160. Additional arguments to celerybeat, see `celerybeat --help` for a
  161. list.
  162. * CELERYBEAT_PIDFILE
  163. Full path to the PID file. Default is /var/run/celeryd.pid.
  164. * CELERYBEAT_LOGFILE
  165. Full path to the celeryd log file. Default is /var/log/celeryd.log
  166. * CELERYBEAT_LOG_LEVEL
  167. Log level to use for celeryd. Default is INFO.
  168. * CELERYBEAT
  169. Path to the celeryd program. Default is `celeryd`.
  170. You can point this to an virtualenv, or even use manage.py for django.
  171. * CELERYBEAT_USER
  172. User to run celeryd as. Default is current user.
  173. * CELERYBEAT_GROUP
  174. Group to run celeryd as. Default is current user.
  175. .. _generic-initd-troubleshooting:
  176. Troubleshooting
  177. ---------------
  178. If you can't get the init scripts to work, you should try running
  179. them in *verbose mode*::
  180. $ sh -x /etc/init.d/celeryd start
  181. This can reveal hints as to why the service won't start.
  182. Also you will see the commands generated, so you can try to run the celeryd
  183. command manually to read the resulting error output.
  184. For example my `sh -x` output does this::
  185. ++ start-stop-daemon --start --chdir /opt/Opal/release/opal --quiet \
  186. --oknodo --background --make-pidfile --pidfile /var/run/celeryd.pid \
  187. --exec /opt/Opal/release/opal/manage.py celeryd -- --time-limit=300 \
  188. -f /var/log/celeryd.log -l INFO
  189. Run the celeryd command after `--exec` (without the `--`) to show the
  190. actual resulting output::
  191. $ /opt/Opal/release/opal/manage.py celeryd --time-limit=300 \
  192. -f /var/log/celeryd.log -l INFO
  193. .. _daemon-supervisord:
  194. `supervisord`_
  195. ==============
  196. * `contrib/supervisord/`_
  197. .. _`contrib/supervisord/`:
  198. http://github.com/celery/celery/tree/master/contrib/supervisord/
  199. .. _`supervisord`: http://supervisord.org/
  200. .. _daemon-launchd:
  201. launchd (OS X)
  202. ==============
  203. * `contrib/mac/`_
  204. .. _`contrib/mac/`:
  205. http://github.com/celery/celery/tree/master/contrib/mac/
  206. .. _daemon-windows:
  207. Windows
  208. =======
  209. See this excellent external tutorial:
  210. http://www.calazan.com/windows-tip-run-applications-in-the-background-using-task-scheduler/