api.rst 10 KB

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