introduction.rst 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. Introduction
  2. ============
  3. Overview
  4. --------
  5. ``supervisor`` is a client/server system that allows its users to
  6. control a number of processes on UNIX-like operating systems. It was
  7. inspired 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. </para> </listitem>
  54. </itemizedlist>
  55. Supervisor Components
  56. ---------------------
  57. :program:`supervisord`
  58. The server piece of supervisor is named :program:`supervisord`. It
  59. is responsible for starting child programs at its own invocation,
  60. responding to commands from clients, restarting crashed or exited
  61. subprocesseses, logging its subprocess ``stdout`` and ``stderr``
  62. output, and generating and handling "events" corresponding to points
  63. in subprocess lifetimes.
  64. The server process uses a configuration file. This is typically
  65. located in :file:`/etc/supervisord.conf`. This configuration file
  66. is an "Windows-INI" style config file. It is important to keep this
  67. file secure via proper filesystem permissions because it may contain
  68. unencrypted usernames and passwords.
  69. :program:`supervisorctl`
  70. The command-line client piece of the supervisor is named
  71. :program:`supervisorctl`. It provides a shell-like interface to the
  72. features provided by :program:`supervisord`. From
  73. :program:`supervisorctl`, a user can connect to different
  74. :program:`supervisord` processes, get status on the subprocesses
  75. controlled by, stop and start subprocesses of, and get lists of
  76. running processes of a :program:`supervisord`.
  77. The command-line client talks to the server across a UNIX domain
  78. socket or an internet (TCP) socket. The server can assert that the
  79. user of a client should present authentication credentials before it
  80. allows him to perform commands. The client process typically uses
  81. the same configuration file as the server but any configuration file
  82. with a ``[supervisorctl]`` section in it will work.
  83. Web Server
  84. A (sparse) web user interface with functionality comparable to
  85. :program:`supervisorctl` may be accessed via a browser if you start
  86. :program:`supervisord` against an internet socket. Visit the server
  87. URL (e.g. ``http://localhost:9001/``) to view and control process
  88. status through the web interface after activating the configuration
  89. file's ``[inet_http_server]`` section.
  90. XML-RPC Interface
  91. The same HTTP server which serves the web UI serves up an XML-RPC
  92. interface that can be used to interrogate and control supervisor and
  93. the programs it runs. To use the XML-RPC interface, connect to
  94. supervisor's http port with any XML-RPC client library and run
  95. commands against it. An example of doing this using Python's
  96. ``xmlrpclib`` client library is as follows.
  97. .. code-block:: python
  98. import xmlrpclib
  99. server = xmlrpclib.Server('http://localhost:9001')
  100. You may call methods against the :program:`supervisord` and its
  101. subprocesses by using the ``supervisor`` namespace. An example is
  102. provided below.
  103. .. code-block:: python
  104. server.supervisor.getState()
  105. You can get a list of methods supported by the
  106. :program:`supervisord` XML-RPC interface by using the XML-RPC
  107. ``system.listMethods`` API:
  108. .. code-block:: python
  109. server.system.listMethods()
  110. You can see help on a method by using the ``system.methodHelp`` API
  111. against the method:
  112. .. code-block:: python
  113. print server.system.methodHelp('supervisor.shutdown')
  114. The :program:`supervisord` XML-RPC interface also supports the
  115. nascent `XML-RPC multicall API
  116. <http://www.xmlrpc.com/discuss/msgReader$1208>`_.
  117. You can extend :program:`supervisord` functionality with new XML-RPC
  118. API methods by adding new top-level RPC interfaces as necessary.
  119. See :ref:`rpcinterface_settings`.
  120. Platform Requirements
  121. ---------------------
  122. Supervisor has been tested and is known to run on Linux (Ubuntu
  123. Dapper/Feisy/Gutsy), Mac OS X (10.4/10.5), and Solaris (10 for Intel)
  124. and FreeBSD 6.1. It will likely work fine on most UNIX systems.
  125. Supervisor will not run at all under any version of Windows.
  126. Supervisor is known to work with Python 2.3.3 or better, and it may
  127. work with Python 2.3.0, Python 2.3.1 and Python 2.3.2 (although these
  128. have not been tested). It will not work at all with Python versions
  129. before 2.3.0. Supervisor is not compatible with Python 3.X.