api.rst 12 KB

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