running.rst 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. .. _running:
  2. Running Supervisor
  3. ==================
  4. This section makes reference to a :envvar:`BINDIR` when explaining how
  5. to run the :command:`supervisord` and :command:`supervisorctl`
  6. commands. This is the "bindir" directory that your Python
  7. installation has been configured with. For example, for an
  8. installation of Python installed via ``./configure
  9. --prefix=/usr/local/py; make; make install``, :envvar:`BINDIR` would
  10. be :file:`/usr/local/py/bin`. Python interpreters on different
  11. platforms use a different :envvar:`BINDIR`. Look at the output of
  12. ``setup.py install`` if you can't figure out where yours is.
  13. Adding a Program
  14. ----------------
  15. Before :program:`supervisord` will do anything useful for you, you'll
  16. need to add at least one ``program`` section to its configuration.
  17. The ``program`` section will define a program that is run and managed
  18. when you invoke the :command:`supervisord` command. To add a program,
  19. you'll need to edit the :file:`supervisord.conf` file.
  20. One of the simplest possible programs to run is the UNIX
  21. :program:`cat` program. A ``program`` section that will run ``cat``
  22. when the :program:`supervisord` process starts up is shown below.
  23. .. code-block:: ini
  24. [program:foo]
  25. command=/bin/cat
  26. This stanza may be cut and pasted into the :file:`supervisord.conf`
  27. file. This is the simplest possible program configuration, because it
  28. only names a command. Program configuration sections have many other
  29. configuration options which aren't shown here. See
  30. :ref:`programx_section` for more information.
  31. Running :program:`supervisord`
  32. ------------------------------
  33. To start :program:`supervisord`, run :file:`$BINDIR/supervisord`. The
  34. resulting process will daemonize itself and detach from the terminal.
  35. It keeps an operations log at :file:`$CWD/supervisor.log` by default.
  36. You may start the :command:`supervisord` executable in the foreground
  37. by passing the ``-n`` flag on its command line. This is useful to
  38. debug startup problems.
  39. .. warning::
  40. When :program:`supervisord` starts up, it will search for its
  41. configuration file in default locations *including the current working
  42. directory*. If you are security-conscious you will probably want to
  43. specify a "-c" argument after the :program:`supervisord` command
  44. specifying an absolute path to a configuration file to ensure that someone
  45. doesn't trick you into running supervisor from within a directory that
  46. contains a rogue ``supervisord.conf`` file. A warning is emitted when
  47. supervisor is started as root without this ``-c`` argument.
  48. To change the set of programs controlled by :program:`supervisord`,
  49. edit the :file:`supervisord.conf` file and ``kill -HUP`` or otherwise
  50. restart the :program:`supervisord` process. This file has several
  51. example program definitions.
  52. The :command:`supervisord` command accepts a number of command-line
  53. options. Each of these command line options overrides any equivalent
  54. value in the configuration file.
  55. :command:`supervisord` Command-Line Options
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. -c FILE, --configuration=FILE
  58. The path to a :program:`supervisord` configuration file.
  59. -n, --nodaemon
  60. Run :program:`supervisord` in the foreground.
  61. -h, --help
  62. Show :command:`supervisord` command help.
  63. -u USER, --user=USER
  64. UNIX username or numeric user id. If :program:`supervisord` is
  65. started as the root user, setuid to this user as soon as possible
  66. during startup.
  67. -m OCTAL, --umask=OCTAL
  68. Octal number (e.g. 022) representing the :term:`umask` that should
  69. be used by :program:`supervisord` after it starts.
  70. -d PATH, --directory=PATH
  71. When supervisord is run as a daemon, cd to this directory before
  72. daemonizing.
  73. -l FILE, --logfile=FILE
  74. Filename path to use as the supervisord activity log.
  75. -y BYTES, --logfile_maxbytes=BYTES
  76. Max size of the supervisord activity log file before a rotation
  77. occurs. The value is suffix-multiplied, e.g "1" is one byte, "1MB"
  78. is 1 megabyte, "1GB" is 1 gigabyte.
  79. -y NUM, --logfile_backups=NUM
  80. Number of backup copies of the supervisord activity log to keep
  81. around. Each logfile will be of size ``logfile_maxbytes``.
  82. -e LEVEL, --loglevel=LEVEL
  83. The logging level at which supervisor should write to the activity
  84. log. Valid levels are ``trace``, ``debug``, ``info``, ``warn``,
  85. ``error``, and ``critical``.
  86. -j FILE, --pidfile=FILE
  87. The filename to which supervisord should write its pid file.
  88. -i STRING, --identifier=STRING
  89. Arbitrary string identifier exposed by various client UIs for this
  90. instance of supervisor.
  91. -q PATH, --childlogdir=PATH
  92. A path to a directory (it must already exist) where supervisor will
  93. write its ``AUTO`` -mode child process logs.
  94. -k, --nocleanup
  95. Prevent :program:`supervisord` from performing cleanup (removal of
  96. old ``AUTO`` process log files) at startup.
  97. -a NUM, --minfds=NUM
  98. The minimum number of file descriptors that must be available to
  99. the supervisord process before it will start successfully.
  100. -t, --strip_ansi
  101. Strip ANSI escape sequences from all child log process.
  102. -v, --version
  103. Print the supervisord version number out to stdout and exit.
  104. --profile_options=LIST
  105. Comma-separated options list for profiling. Causes
  106. :program:`supervisord` to run under a profiler, and output results
  107. based on the options, which is a comma-separated list of the
  108. following: ``cumulative``, ``calls``, ``callers``.
  109. E.g. ``cumulative,callers``.
  110. --minprocs=NUM
  111. The minimum number of OS process slots that must be available to
  112. the supervisord process before it will start successfully.
  113. :command:`supervisorctl` Command-Line Options
  114. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. -c, --configuration
  116. Configuration file path (default /etc/supervisord.conf)
  117. -h, --help
  118. Print usage message and exit
  119. -i, --interactive
  120. Start an interactive shell after executing commands
  121. -s, --serverurl URL
  122. URL on which supervisord server is listening (default "http://localhost:9001").
  123. -u, --username
  124. Username to use for authentication with server
  125. -p, --password
  126. Password to use for authentication with server
  127. -r, --history-file
  128. Keep a readline history (if readline is available)
  129. `action [arguments]`
  130. Actions are commands like "tail" or "stop". If -i is specified or no action is
  131. specified on the command line, a "shell" interpreting actions typed
  132. interactively is started. Use the action "help" to find out about available
  133. actions.
  134. Running :program:`supervisorctl`
  135. --------------------------------
  136. To start :program:`supervisorctl`, run ``$BINDIR/supervisorctl``. A
  137. shell will be presented that will allow you to control the processes
  138. that are currently managed by :program:`supervisord`. Type "help" at
  139. the prompt to get information about the supported commands.
  140. The :command:`supervisorctl` executable may be invoked with "one time"
  141. commands when invoked with arguments from a command line. An example:
  142. ``supervisorctl stop all``. If arguments are present on the
  143. command-line, it will prevent the interactive shell from being
  144. invoked. Instead, the command will be executed and
  145. ``supervisorctl`` will exit.
  146. If :command:`supervisorctl` is invoked in interactive mode against a
  147. :program:`supervisord` that requires authentication, you will be asked
  148. for authentication credentials.
  149. Signals
  150. -------
  151. The :program:`supervisord` program may be sent signals which cause it
  152. to perform certain actions while it's running.
  153. You can send any of these signals to the single :program:`supervisord`
  154. process id. This process id can be found in the file represented by
  155. the ``pidfile`` parameter in the ``[supervisord]`` section of the
  156. configuration file (by default it's :file:`$CWD/supervisord.pid`).
  157. Signal Handlers
  158. ~~~~~~~~~~~~~~~
  159. ``SIGTERM``
  160. :program:`supervisord` and all its subprocesses will shut down.
  161. This may take several seconds.
  162. ``SIGINT``
  163. :program:`supervisord` and all its subprocesses will shut down.
  164. This may take several seconds.
  165. ``SIGQUIT``
  166. :program:`supervisord` and all its subprocesses will shut down.
  167. This may take several seconds.
  168. ``SIGHUP``
  169. :program:`supervisord` will stop all processes, reload the
  170. configuration from the first config file it finds, and restart all
  171. processes.
  172. ``SIGUSR2``
  173. :program:`supervisord` will close and reopen the main activity log
  174. and all child log files.
  175. Runtime Security
  176. ----------------
  177. The developers have done their best to assure that use of a
  178. :program:`supervisord` process running as root cannot lead to
  179. unintended privilege escalation. But **caveat emptor**. Supervisor
  180. is not as paranoid as something like DJ Bernstein's
  181. :term:`daemontools`, inasmuch as :program:`supervisord` allows for
  182. arbitrary path specifications in its configuration file to which data
  183. may be written. Allowing arbitrary path selections can create
  184. vulnerabilities from symlink attacks. Be careful when specifying
  185. paths in your configuration. Ensure that the :program:`supervisord`
  186. configuration file cannot be read from or written to by unprivileged
  187. users and that all files installed by the supervisor package have
  188. "sane" file permission protection settings. Additionally, ensure that
  189. your ``PYTHONPATH`` is sane and that all Python standard
  190. library files have adequate file permission protections.
  191. Running :program:`supervisord` automatically on startup
  192. -------------------------------------------------------
  193. If you are using a distribution-packaged version of Supervisor, it should
  194. already be integrated into the service management infrastructure of your
  195. distribution.
  196. There are user-contributed scripts for various operating systems at:
  197. https://github.com/Supervisor/initscripts
  198. There are some answers at Serverfault in case you get stuck:
  199. `How to automatically start supervisord on Linux (Ubuntu)`__
  200. .. __: http://serverfault.com/questions/96499/how-to-automatically-start-supervisord-on-linux-ubuntu