running.rst 7.6 KB

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