api.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. .. _xml_rpc:
  2. XML-RPC API Documentation
  3. =========================
  4. To use the XML-RPC interface, connect to supervisor's HTTP port
  5. with any XML-RPC client library and run commands against it. An
  6. example of doing this using Python's ``xmlrpclib`` client library
  7. is as follows.
  8. .. code-block:: python
  9. import xmlrpclib
  10. server = xmlrpclib.Server('http://localhost:9001/RPC2')
  11. You may call methods against :program:`supervisord` and its
  12. subprocesses by using the ``supervisor`` namespace. An example is
  13. provided below.
  14. .. code-block:: python
  15. server.supervisor.getState()
  16. You can get a list of methods supported by the
  17. :program:`supervisord` XML-RPC interface by using the XML-RPC
  18. ``system.listMethods`` API:
  19. .. code-block:: python
  20. server.system.listMethods()
  21. You can see help on a method by using the ``system.methodHelp`` API
  22. against the method:
  23. .. code-block:: python
  24. server.system.methodHelp('supervisor.shutdown')
  25. The :program:`supervisord` XML-RPC interface also supports the
  26. `XML-RPC multicall API
  27. <http://web.archive.org/web/20060824100531/http://www.xmlrpc.com/discuss/msgReader$1208>`_.
  28. You can extend :program:`supervisord` functionality with new XML-RPC
  29. API methods by adding new top-level RPC interfaces as necessary.
  30. See :ref:`rpcinterface_factories`.
  31. .. automodule:: supervisor.rpcinterface
  32. Status and Control
  33. ------------------
  34. .. autoclass:: SupervisorNamespaceRPCInterface
  35. .. automethod:: getAPIVersion
  36. This API is versioned separately from Supervisor itself. The API version
  37. returned by ``getAPIVersion`` only changes when the API changes. Its purpose
  38. is to help the client identify with which version of the Supervisor API it
  39. is communicating.
  40. When writing software that communicates with this API, it is highly
  41. recommended that you first test the API version for compatibility before
  42. making method calls.
  43. .. note::
  44. The ``getAPIVersion`` method replaces ``getVersion`` found in Supervisor
  45. versions prior to 3.0a1. It is aliased for compatibility but getVersion()
  46. is deprecated and support will be dropped from Supervisor in a future
  47. version.
  48. .. automethod:: getSupervisorVersion
  49. .. automethod:: getIdentification
  50. This method allows the client to identify with which Supervisor
  51. instance it is communicating in the case of environments where
  52. multiple Supervisors may be running.
  53. The identification is a string that must be set in Supervisor’s
  54. configuration file. This method simply returns that value back to the
  55. client.
  56. .. automethod:: getState
  57. This is an internal value maintained by Supervisor that determines what
  58. Supervisor believes to be its current operational state.
  59. Some method calls can alter the current state of the Supervisor. For
  60. example, calling the method supervisor.shutdown() while the station is
  61. in the RUNNING state places the Supervisor in the SHUTDOWN state while
  62. it is shutting down.
  63. The supervisor.getState() method provides a means for the client to check
  64. Supervisor's state, both for informational purposes and to ensure that the
  65. methods it intends to call will be permitted.
  66. The return value is a struct:
  67. .. code-block:: python
  68. {'statecode': 1,
  69. 'statename': 'RUNNING'}
  70. The possible return values are:
  71. +---------+----------+----------------------------------------------+
  72. |statecode|statename |Description |
  73. +=========+==========+==============================================+
  74. | 2 |FATAL |Supervisor has experienced a serious error. |
  75. +---------+----------+----------------------------------------------+
  76. | 1 |RUNNING |Supervisor is working normally. |
  77. +---------+----------+----------------------------------------------+
  78. | 0 |RESTARTING|Supervisor is in the process of restarting. |
  79. +---------+----------+----------------------------------------------+
  80. | -1 |SHUTDOWN |Supervisor is in the process of shutting down.|
  81. +---------+----------+----------------------------------------------+
  82. The ``FATAL`` state reports unrecoverable errors, such as internal
  83. errors inside Supervisor or system runaway conditions. Once set to
  84. ``FATAL``, the Supervisor can never return to any other state without
  85. being restarted.
  86. In the ``FATAL`` state, all future methods except
  87. supervisor.shutdown() and supervisor.restart() will automatically fail
  88. without being called and the fault ``FATAL_STATE`` will be raised.
  89. In the ``SHUTDOWN`` or ``RESTARTING`` states, all method calls are
  90. ignored and their possible return values are undefined.
  91. .. automethod:: getPID
  92. .. automethod:: readLog
  93. It can either return the entire log, a number of characters from the
  94. tail of the log, or a slice of the log specified by the offset and
  95. length parameters:
  96. +--------+---------+------------------------------------------------+
  97. | Offset | Length | Behavior of ``readProcessLog`` |
  98. +========+=========+================================================+
  99. |Negative|Not Zero | Bad arguments. This will raise the fault |
  100. | | | ``BAD_ARGUMENTS``. |
  101. +--------+---------+------------------------------------------------+
  102. |Negative|Zero | This will return the tail of the log, or offset|
  103. | | | number of characters from the end of the log. |
  104. | | | For example, if ``offset`` = -4 and ``length`` |
  105. | | | = 0, then the last four characters will be |
  106. | | | returned from the end of the log. |
  107. +--------+---------+------------------------------------------------+
  108. |Zero or |Negative | Bad arguments. This will raise the fault |
  109. |Positive| | ``BAD_ARGUMENTS``. |
  110. +--------+---------+------------------------------------------------+
  111. |Zero or |Zero | All characters will be returned from the |
  112. |Positive| | ``offset`` specified. |
  113. +--------+---------+------------------------------------------------+
  114. |Zero or |Positive | A number of characters length will be returned |
  115. |Positive| | from the ``offset``. |
  116. +--------+---------+------------------------------------------------+
  117. If the log is empty and the entire log is requested, an empty string
  118. is returned.
  119. If either offset or length is out of range, the fault
  120. ``BAD_ARGUMENTS`` will be returned.
  121. If the log cannot be read, this method will raise either the
  122. ``NO_FILE`` error if the file does not exist or the ``FAILED`` error
  123. if any other problem was encountered.
  124. .. note::
  125. The readLog() method replaces readMainLog() found in Supervisor
  126. versions prior to 2.1. It is aliased for compatibility but
  127. readMainLog() is deprecated and support will be dropped from
  128. Supervisor in a future version.
  129. .. automethod:: clearLog
  130. If the log cannot be cleared because the log file does not exist, the
  131. fault ``NO_FILE`` will be raised. If the log cannot be cleared for any
  132. other reason, the fault ``FAILED`` will be raised.
  133. .. automethod:: shutdown
  134. This method shuts down the Supervisor daemon. If any processes are running,
  135. they are automatically killed without warning.
  136. Unlike most other methods, if Supervisor is in the ``FATAL`` state,
  137. this method will still function.
  138. .. automethod:: restart
  139. This method soft restarts the Supervisor daemon. If any processes are
  140. running, they are automatically killed without warning. Note that the
  141. actual UNIX process for Supervisor cannot restart; only Supervisor’s
  142. main program loop. This has the effect of resetting the internal
  143. states of Supervisor.
  144. Unlike most other methods, if Supervisor is in the ``FATAL`` state,
  145. this method will still function.
  146. Process Control
  147. ---------------
  148. .. autoclass:: SupervisorNamespaceRPCInterface
  149. .. automethod:: getProcessInfo
  150. The return value is a struct:
  151. .. code-block:: python
  152. {'name': 'process name',
  153. 'group': 'group name',
  154. 'start': 1200361776,
  155. 'stop': 0,
  156. 'now': 1200361812,
  157. 'state': 1,
  158. 'statename': 'RUNNING',
  159. 'spawnerr': '',
  160. 'exitstatus': 0,
  161. 'stdout_logfile': '/path/to/stdout-log',
  162. 'stderr_logfile': '/path/to/stderr-log',
  163. 'pid': 1}
  164. .. describe:: name
  165. Name of the process
  166. .. describe:: group
  167. Name of the process' group
  168. .. describe:: start
  169. UNIX timestamp of when the process was started
  170. .. describe:: stop
  171. UNIX timestamp of when the process ended, or 0 if the process is
  172. still running.
  173. .. describe:: now
  174. UNIX timestamp of the current time, which can be used to calculate
  175. process up-time.
  176. .. describe:: state
  177. State code, see table below.
  178. .. describe:: statename
  179. String description of `state`, see table below.
  180. .. describe:: stdout_logfile
  181. Absolute path and filename to the STDOUT logfile
  182. .. describe:: stderr_logfile
  183. Absolute path and filename to the STDOUT logfile
  184. .. describe:: spawnerr
  185. Description of error that occurred during spawn, or empty string
  186. if none.
  187. .. describe:: exitstatus
  188. Exit status (errorlevel) of process, or 0 if the process is still
  189. running.
  190. .. describe:: pid
  191. UNIX process ID (PID) of the process, or 0 if the process is not
  192. running.
  193. .. automethod:: getAllProcessInfo
  194. Each element contains a struct, and this struct contains the exact
  195. same elements as the struct returned by ``getProcess``. If the process
  196. table is empty, an empty array is returned.
  197. .. automethod:: startProcess
  198. .. automethod:: startAllProcesses
  199. .. automethod:: startProcessGroup
  200. .. automethod:: stopProcessGroup
  201. .. automethod:: sendProcessStdin
  202. .. automethod:: sendRemoteCommEvent
  203. .. automethod:: addProcessGroup
  204. .. automethod:: removeProcessGroup
  205. Process Logging
  206. ---------------
  207. .. autoclass:: SupervisorNamespaceRPCInterface
  208. .. automethod:: readProcessStdoutLog
  209. .. automethod:: readProcessStderrLog
  210. .. automethod:: tailProcessStdoutLog
  211. .. automethod:: tailProcessStderrLog
  212. .. automethod:: clearProcessLogs
  213. .. automethod:: clearAllProcessLogs
  214. .. automodule:: supervisor.xmlrpc
  215. System Methods
  216. --------------
  217. .. autoclass:: SystemNamespaceRPCInterface
  218. .. automethod:: listMethods
  219. .. automethod:: methodHelp
  220. .. automethod:: methodSignature
  221. .. automethod:: multicall