introduction.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. Introduction
  2. ============
  3. Overview
  4. --------
  5. Supervisor is a client/server system that allows its users to control
  6. a number of processes on UNIX-like operating systems. It was inspired
  7. by the following:
  8. Convenience
  9. It is often inconvenient to need to write ``rc.d`` scripts for every
  10. single process instance. ``rc.d`` scripts are a great
  11. lowest-common-denominator form of process
  12. initialization/autostart/management, but they can be painful to
  13. write and maintain. Additionally, ``rc.d`` scripts cannot
  14. automatically restart a crashed process and many programs do not
  15. restart themselves properly on a crash. Supervisord starts
  16. processes as its subprocesses, and can be configured to
  17. automatically restart them on a crash. It can also automatically be
  18. configured to start processes on its own invocation.
  19. Accuracy
  20. It's often difficult to get accurate up/down status on processes on
  21. UNIX. Pidfiles often lie. Supervisord starts processes as
  22. subprocesses, so it always knows the true up/down status of its
  23. children and can be queried conveniently for this data.
  24. Delegation
  25. Users who need to control process state often need only to do that.
  26. They don't want or need full-blown shell access to the machine on
  27. which the processes are running. Processes which listen on "low"
  28. TCP ports often need to be started and restarted as the root user (a
  29. UNIX misfeature). It's usually the case that it's perfectly fine to
  30. allow "normal" people to stop or restart such a process, but
  31. providing them with shell access is often impractical, and providing
  32. them with root access or sudo access is often impossible. It's also
  33. (rightly) difficult to explain to them why this problem exists. If
  34. supervisord is started as root, it is possible to allow "normal"
  35. users to control such processes without needing to explain the
  36. intricacies of the problem to them. Supervisorctl allows a very
  37. limited form of access to the machine, essentially allowing users to
  38. see process status and control supervisord-controlled subprocesses
  39. by emitting "stop", "start", and "restart" commands from a simple
  40. shell or web UI.
  41. Distributed Control
  42. Users often need to control processes on many machines. Supervisor
  43. provides a simple, secure, and uniform mechanism for interactively
  44. and automatically controlling processes on groups of machines.
  45. Process Groups
  46. Processes often need to be started and stopped in groups, sometimes
  47. even in a "priority order". It's often difficult to explain to
  48. people how to do this. Supervisor allows you to assign priorities
  49. to processes, and allows user to emit commands via the supervisorctl
  50. client like "start all", and "restart all", which starts them in the
  51. preassigned priority order. Additionally, processes can be grouped
  52. into "process groups" and a set of logically related processes can
  53. be stopped and started as a unit.
  54. Features
  55. --------
  56. Simple
  57. Supervisor is configured through a simple INI-style config file
  58. that’s easy to learn. It provides many per-process options that make
  59. your life easier like restarting failed processes and automatic log
  60. rotation.
  61. Centralized
  62. Supervisor provides you with one place to start, stop, and monitor
  63. your processes. Processes can be controlled individually or in
  64. groups. You can configure Supervisor to provide a local or remote
  65. command line and web interface.
  66. Efficient
  67. Supervisor starts its subprocesses via fork/exec and subprocesses
  68. don’t daemonize. The operating system signals Supervisor immediately
  69. when a process terminates, unlike some solutions that rely on
  70. troublesome PID files and periodic polling to restart failed
  71. processes.
  72. Extensible
  73. Supervisor has a simple event notification protocol that programs
  74. written in any language can use to monitor it, and an XML-RPC
  75. interface for control. It is also built with extension points that
  76. can be leveraged by Python developers.
  77. Compatible
  78. Supervisor works on just about everything except for Windows. It is
  79. tested and supported on Linux, Mac OS X, Solaris, and FreeBSD. It is
  80. written entirely in Python, so installation does not require a C
  81. compiler.
  82. Proven
  83. While Supervisor is very actively developed today, it is not new
  84. software. Supervisor has been around for years and is already in use
  85. on many servers.
  86. Supervisor Components
  87. ---------------------
  88. :program:`supervisord`
  89. The server piece of supervisor is named :program:`supervisord`. It
  90. is responsible for starting child programs at its own invocation,
  91. responding to commands from clients, restarting crashed or exited
  92. subprocesseses, logging its subprocess ``stdout`` and ``stderr``
  93. output, and generating and handling "events" corresponding to points
  94. in subprocess lifetimes.
  95. The server process uses a configuration file. This is typically
  96. located in :file:`/etc/supervisord.conf`. This configuration file
  97. is an "Windows-INI" style config file. It is important to keep this
  98. file secure via proper filesystem permissions because it may contain
  99. unencrypted usernames and passwords.
  100. :program:`supervisorctl`
  101. The command-line client piece of the supervisor is named
  102. :program:`supervisorctl`. It provides a shell-like interface to the
  103. features provided by :program:`supervisord`. From
  104. :program:`supervisorctl`, a user can connect to different
  105. :program:`supervisord` processes, get status on the subprocesses
  106. controlled by, stop and start subprocesses of, and get lists of
  107. running processes of a :program:`supervisord`.
  108. The command-line client talks to the server across a UNIX domain
  109. socket or an internet (TCP) socket. The server can assert that the
  110. user of a client should present authentication credentials before it
  111. allows him to perform commands. The client process typically uses
  112. the same configuration file as the server but any configuration file
  113. with a ``[supervisorctl]`` section in it will work.
  114. Web Server
  115. A (sparse) web user interface with functionality comparable to
  116. :program:`supervisorctl` may be accessed via a browser if you start
  117. :program:`supervisord` against an internet socket. Visit the server
  118. URL (e.g. ``http://localhost:9001/``) to view and control process
  119. status through the web interface after activating the configuration
  120. file's ``[inet_http_server]`` section.
  121. XML-RPC Interface
  122. The same HTTP server which serves the web UI serves up an XML-RPC
  123. interface that can be used to interrogate and control supervisor and
  124. the programs it runs. To use the XML-RPC interface, connect to
  125. supervisor's http port with any XML-RPC client library and run
  126. commands against it. An example of doing this using Python's
  127. ``xmlrpclib`` client library is as follows.
  128. .. code-block:: python
  129. import xmlrpclib
  130. server = xmlrpclib.Server('http://localhost:9001/RPC2')
  131. You may call methods against the :program:`supervisord` and its
  132. subprocesses by using the ``supervisor`` namespace. An example is
  133. provided below.
  134. .. code-block:: python
  135. server.supervisor.getState()
  136. You can get a list of methods supported by the
  137. :program:`supervisord` XML-RPC interface by using the XML-RPC
  138. ``system.listMethods`` API:
  139. .. code-block:: python
  140. server.system.listMethods()
  141. You can see help on a method by using the ``system.methodHelp`` API
  142. against the method:
  143. .. code-block:: python
  144. print server.system.methodHelp('supervisor.shutdown')
  145. The :program:`supervisord` XML-RPC interface also supports the
  146. nascent `XML-RPC multicall API
  147. <http://www.xmlrpc.com/discuss/msgReader$1208>`_.
  148. You can extend :program:`supervisord` functionality with new XML-RPC
  149. API methods by adding new top-level RPC interfaces as necessary.
  150. See :ref:`rpcinterface_factories`.
  151. Platform Requirements
  152. ---------------------
  153. Supervisor has been tested and is known to run on Linux (Ubuntu 9.10),
  154. Mac OS X (10.4/10.5/10.6), and Solaris (10 for Intel) and FreeBSD 6.1.
  155. It will likely work fine on most UNIX systems.
  156. Supervisor will *not* run at all under any version of Windows.
  157. Supervisor is known to work with Python 2.3.3 or better, and it may
  158. work with Python 2.3.0, Python 2.3.1 and Python 2.3.2 (although these
  159. have not been tested). It will not work at all with Python versions
  160. before 2.3.0. Supervisor is not compatible with Python 3.X.