README.txt 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. Supervisor: A System for Allowing the Control of Process State on UNIX
  2. History
  3. 7/3/2006: updated for version 2.0
  4. 8/30/2006: updated for version 2.1
  5. 3/31/2007: updated for version 2.2
  6. 8/15/2007: updated for version 3.0a1
  7. 8/21/2007: updated for version 3.0a2
  8. Upgrading
  9. If you are upgrading from supervisor version 2.X to version 3.X, and
  10. you wish to preserve your supervisor configuration file, you will
  11. need to read the file named 'UPGRADING.txt' within the same
  12. directory as this file. Some configuration file options have
  13. changed and new ones have been added.
  14. Introduction
  15. The supervisor is a client/server system that allows its users to
  16. control a number of processes on UNIX-like operating systems. It
  17. was inspired by the following:
  18. - It is often inconvenient to need to write "rc.d" scripts for
  19. every single process instance. rc.d scripts are a great
  20. lowest-common-denominator form of process
  21. initialization/autostart/management, but they can be painful to
  22. write and maintain. Additionally, rc.d scripts cannot
  23. automatically restart a crashed process and many programs do not
  24. restart themselves properly on a crash. Supervisord starts
  25. processes as its subprocesses, and can be configured to
  26. automatically restart them on a crash. It can also automatically
  27. be configured to start processes on its own invocation.
  28. - It's often difficult to get accurate up/down status on processes
  29. on UNIX. Pidfiles often lie. Supervisord starts processes as
  30. subprocesses, so it always knows the true up/down status of its
  31. children and can be queried conveniently for this data.
  32. - Users who need to control process state often need only to do
  33. that. They don't want or need full-blown shell access to the
  34. machine on which the processes are running. Supervisorctl allows
  35. a very limited form of access to the machine, essentially
  36. allowing users to see process status and control
  37. supervisord-controlled subprocesses by emitting "stop", "start",
  38. and "restart" commands from a simple shell or web UI.
  39. - Users often need to control processes on many machines.
  40. Supervisor provides a simple, secure, and uniform mechanism for
  41. interactively and automatically controlling processes on groups
  42. of machines.
  43. - Processes which listen on "low" TCP ports often need to be
  44. started and restarted as the root user (a UNIX misfeature). It's
  45. usually the case that it's perfectly fine to allow "normal"
  46. people to stop or restart such a process, but providing them with
  47. shell access is often impractical, and providing them with root
  48. access or sudo access is often impossible. It's also (rightly)
  49. difficult to explain to them why this problem exists. If
  50. supervisord is started as root, it is possible to allow "normal"
  51. users to control such processes without needing to explain the
  52. intricacies of the problem to them.
  53. - Processes often need to be started and stopped in groups,
  54. sometimes even in a "priority order". It's often difficult to
  55. explain to people how to do this. Supervisor allows you to
  56. assign priorities to processes, and allows user to emit commands
  57. via the supervisorctl client like "start all", and "restart all",
  58. which starts them in the preassigned priority order.
  59. Additionally, processes can be grouped into "process groups" and
  60. a set of logically related processes can be stopped and started
  61. as a unit.
  62. Supported Platforms
  63. Supervisor has been tested and is known to run on Linux (Ubuntu
  64. Dapper), Mac OS X (10.4), and Solaris (10 for Intel) and FreeBSD
  65. 6.1. It will likely work fine on most UNIX systems.
  66. Supervisor will not run at all under any version of Windows.
  67. Supervisor is known to work with Python 2.3.3 or better, and it may
  68. work with Python 2.3.0, Python 2.3.1 and Python 2.3.2 (although
  69. these have not been tested). It will not work under Python versions
  70. 2.2 or before.
  71. Installing
  72. Run "python setup.py install". This will download and install all
  73. distributions depended upon by supervisor and finally install
  74. supervisor itself. Once that's done, copy the "sample.conf" file
  75. you'll find in the same directory as this file (or within the
  76. installed supervisor egg's 'doc' directory) to /etc/supervisord.conf
  77. and modify to your liking. If you'd rather not put the
  78. supervisord.conf file in /etc, you can place it anywhere and start
  79. supervisord and point it at the configuration file via the -c flag,
  80. e.g. "python supervisord.py -c /path/to/sample/conf" or, if you use
  81. the shell script named "supervisord", "supervisord -c
  82. /path/to/sample.conf".
  83. If your system does not have a C compiler, or you don't have
  84. Python's development libraries and include files installed,
  85. 'setup.py install' will fail, as by default, at least one of
  86. supervisor's dependent distributions, meld3, attempts to compile C
  87. extensions that use the Python C API. These extensions are
  88. optional, and meld3 (as of its release 0.6.1) will work fine without
  89. them. To avoid attempting to compile meld3 extensions, set the
  90. environment variable "NO_MELD3_EXTENSION_MODULES=1" in the shell in
  91. which you invoke supervisor's 'setup.py install' command, e.g.::
  92. NO_MELD3_EXTENSION_MODULES=1 python setup.py install
  93. This will cause meld3 to skip attempting to build its extensions,
  94. and thus supervisor's installation will succeed.
  95. I make reference below to a "$BINDIR" when explaining how to run
  96. supervisord and supervisorctl. This is the "bindir" directory that
  97. your Python installation has been configured with. For example, for
  98. an installation of Python installed via "./configure
  99. --prefix=/usr/local/python; make; make install", $BINDIR would be
  100. "/usr/local/python/bin". Python interpreters on different platforms
  101. use different $BINDIRs. Look at the output of "setup.py install" if
  102. you can't figure out where yours is.
  103. Installing Without Internet Access
  104. Since "setup.py install" performs downloads of dependent software,
  105. it will not work on machines without internet access. To install to
  106. a machine which is not internet connected, obtain the following
  107. dependencies on a machine which is internet-connected:
  108. - setuptools (latest) from http://pypi.python.org/pypi/setuptools
  109. - meld3 (0.6) from http://www.plope.com/software/meld3/
  110. - medusa (0.5.4) from http://www.amk.ca/python/code/medusa.html
  111. - elementtree (1.2.6) from http://effbot.org/downloads#elementtree
  112. And then copy these files to removable media and put them on the
  113. target machine. Install each onto the target machine as per its
  114. instructions.
  115. Finally, run supervisor's "python setup.py install" or
  116. "NO_MELD3_EXTENSION_MODULES=1 python.setup.py install" (see
  117. explanation in the 'Installing' section).
  118. Running Supervisord
  119. To start supervisord, run $BINDIR/supervisord. The resulting
  120. process will daemonize itself and detach from the terminal. It
  121. keeps an operations log at "/tmp/supervisor.log" by default.
  122. You can start supervisord in the foreground by passing the "-n" flag
  123. on its command line. This is useful to debug startup problems.
  124. To change the set of programs controlled by supervisord, edit the
  125. supervisord.conf file and kill -HUP or otherwise restart the
  126. supervisord process. This file has several example program
  127. definitions.
  128. Supervisord accepts a number of command-line overrides. Type
  129. 'supervisord -h' for an overview.
  130. Running Supervisorctl
  131. To start supervisorctl, run $BINDIR/supervisorctl. A shell will
  132. be presented that will allow you to control the processes that are
  133. currently managed by supervisord. Type "help" at the prompt to get
  134. information about the supported commands.
  135. supervisorctl may be invoked with "one time" commands when invoked
  136. with arguments from a command line. An example: "supervisorctl stop
  137. all". If arguments are present on the supervisorctl command-line,
  138. it will prevent the interactive shell from being invoked. Instead,
  139. the command will be executed and supervisorctl will exit.
  140. If supervisorctl is invoked in interactive mode against a
  141. supervisord that requires authentication, you will be asked for
  142. authentication credentials.
  143. Components
  144. Supervisord
  145. The server piece of the supervisor is named "supervisord". It is
  146. responsible for responding to commands from the client process as
  147. well as restarting crashed or exited processes. It is meant to be
  148. run as the root user in most production setups. NOTE: see
  149. "Security Notes" at the end of this document for caveats!
  150. The server process uses a configuration file. This is typically
  151. located in "/etc/supervisord.conf". This configuration file is an
  152. "Windows-INI" style config file. It is important to keep this
  153. file secure via proper filesystem permissions because it may
  154. contain unencrypted usernames and passwords.
  155. Supervisorctl
  156. The command-line client piece of the supervisor is named
  157. "supervisorctl". It provides a shell-like interface to the
  158. features provided by supervisord. From supervisorctl, a user can
  159. connect to different supervisord processes, get status on the
  160. subprocesses controlled by a supervisord, stop and start
  161. subprocesses of a supervisord, and get lists of running processes
  162. of a supervisord.
  163. The command-line client talks to the server across a UNIX domain
  164. socket or an Internet socket. The server can assert that the user
  165. of a client should present authentication credentials before it
  166. allows him to perform commands. The client process may use the
  167. same configuration file as the server; any configuration file with
  168. a [supervisorctl] section in it will work.
  169. Web Server
  170. A (sparse) web user interface with functionality comparable to
  171. supervisorctl may be accessed via a browser if you start
  172. supervisord against an internet socket. Visit the server URL
  173. (e.g. http://localhost:9001/) to view and control process status
  174. through the web interface after changing the configuration file's
  175. 'http_port' parameter appropriately.
  176. XML-RPC Interface
  177. The same HTTP server which serves the web UI serves up an XML-RPC
  178. interface that can be used to interrogate and control supervisor
  179. and the programs it runs. To use the XML-RPC interface, connect
  180. to supervisor's http port with any XML-RPC client library and run
  181. commands against it. An example of doing this using Python's
  182. xmlrpclib client library::
  183. import xmlrpclib
  184. server = xmlrpclib.Server('http://localhost:9001')
  185. Call methods against the supervisor and its subprocesses by using
  186. the 'supervisor' namespace::
  187. server.supervisor.getState()
  188. You can get a list of methods supported by supervisor's XML-RPC
  189. interface by using the XML-RPC 'system.listMethods' API::
  190. server.system.listMethods()
  191. You can see help on a method by using the 'system.methodHelp' API
  192. against the method::
  193. print server.system.methodHelp('supervisor.shutdown')
  194. Supervisor's XML-RPC interface also supports the nascent XML-RPC
  195. multicall API described at
  196. http://www.xmlrpc.com/discuss/msgReader$1208.
  197. You can extend supervisor functionality with new XML-RPC API
  198. methods by adding new top-level RPC interfaces as necessary. See
  199. "Configuration File ['rpcinterface:x] Section Settings" in this
  200. file.
  201. Configuration File '[supervisord]' Section Settings
  202. The supervisord.conf log file contains a section named
  203. '[supervisord]' in which global settings for the supervisord process
  204. should be inserted. These are:
  205. 'http_port' -- Either a TCP host:port value or (e.g. 127.0.0.1:9001)
  206. or a path to a UNIX domain socket (e.g. /tmp/supervisord.sock) on
  207. which supervisor will listen for HTTP/XML-RPC requests.
  208. Supervisorctl itself uses XML-RPC to communicate with supervisord
  209. over this port.
  210. 'sockchmod' -- Change the UNIX permission mode bits of the http_port
  211. UNIX domain socket to this value (ignored if using a TCP socket).
  212. Default: 0700.
  213. 'sockchown' -- Change the user and group of the socket file to this
  214. value. May be a username (e.g. chrism) or a username and group
  215. separated by a dot (e.g. chrism.wheel) Default: do not change.
  216. 'umask' -- The umask of the supervisord process. Default: 022.
  217. 'logfile' -- The path to the activity log of the supervisord process.
  218. 'logfile_maxbytes' -- The maximum number of bytes that may be
  219. consumed by the activity log file before it is rotated (suffix
  220. multipliers like "KB", "MB", and "GB" can be used in the value).
  221. Set this value to 0 to indicate an unlimited log size. Default:
  222. 50MB.
  223. 'logfile_backups' -- The number of backups to keep around resulting
  224. from activity log file rotation. Set this to 0 to indicate an
  225. unlimited number of backups. Default: 10.
  226. 'loglevel' -- The logging level, dictating what is written to the
  227. activity log. One of 'critical', 'error', 'warn', 'info', 'debug'
  228. or 'trace'. Note that at log level 'trace', the supervisord log
  229. file will record the stderr/stdout output of its child processes,
  230. which is useful for debugging. Default: info.
  231. 'pidfile' -- The location in which supervisord keeps its pid file.
  232. 'nodaemon' -- If true, supervisord will start in the foreground
  233. instead of daemonizing. Default: false.
  234. 'minfds' -- The minimum number of file descriptors that must be
  235. available before supervisord will start successfully. Default:
  236. 1024.
  237. 'minprocs' -- The minimum nymber of process descriptors that must be
  238. available before supervisord will start successfully. Default: 200.
  239. 'nocleanup' -- prevent supervisord from clearing any existing "AUTO"
  240. log files at startup time. Default: false.
  241. 'http_username' -- the username required for authentication to our
  242. HTTP server. Default: none.
  243. 'http_password' -- the password required for authentication to our
  244. HTTP server. Default: none.
  245. 'childlogdir' -- the directory used for AUTO log files. Default:
  246. value of Python's tempfile.get_tempdir().
  247. 'user' -- if supervisord is run as root, switch users to this UNIX
  248. user account before doing any meaningful processing. This value has
  249. no effect if supervisord is not run as root. Default: do not switch
  250. users.
  251. 'directory' -- When supervisord daemonizes, switch to this
  252. directory. Default: do not cd.
  253. 'strip_ansi' -- Strip all ANSI escape sequences from process log
  254. files.
  255. 'environment' -- A list of key/value pairs in the form
  256. "KEY=val,KEY2=val2" that will be placed in the supervisord process'
  257. environment (and as a result in all of its child process'
  258. environments). Default: none. **Note** that subprocesses will
  259. inherit the environment variables of the shell used to start
  260. "supervisord" except for the ones overridden here and within the
  261. program's "environment" configuration stanza. See "Subprocess
  262. Environment" below.
  263. 'identifier' -- The identifier for this supervisor server, used by
  264. the RPC interface. Default: 'supervisor'.
  265. Configuration File '[supervisorctl]' Section Settings
  266. The configuration file may contain settings for the supervisorctl
  267. interactive shell program. These options are listed below.
  268. 'serverurl' -- The URL that should be used to access the supervisord
  269. server, e.g. "http://localhost:9001". For UNIX domain sockets, use
  270. "unix:///absolute/path/to/file.sock".
  271. 'username' -- The username to pass to the supervisord server for use
  272. in authentication (should be same as 'http_username' in supervisord
  273. config). Optional.
  274. 'password' -- The password to pass to the supervisord server for use
  275. in authentication (should be the same as 'http_password' in
  276. supervisord config). Optional.
  277. 'prompt' -- String used as supervisorctl prompt. Default: supervisor.
  278. Configuration File '[program:x]' Section Settings
  279. The .INI file must contain one or more 'program' sections in order
  280. for supervisord to know which programs it should start and control.
  281. A sample program section has the following structure, the options of
  282. which are described below it::
  283. [program:foo]
  284. command=/path/to/foo
  285. process_name = %(program_name)s
  286. numprocs=1
  287. priority=1
  288. autostart=true
  289. autorestart=unexpected
  290. startsecs=1
  291. startretries=3
  292. exitcodes=0,2
  293. stopsignal=TERM
  294. stopwaitsecs=10
  295. user=nobody
  296. redirect_stderr=false
  297. stdout_logfile=AUTO
  298. stdout_logfile_maxbytes=50MB
  299. stdout_logfile_backups=10
  300. stdout_capturefile=NONE
  301. stderr_logfile=AUTO
  302. stderr_logfile_maxbytes=50MB
  303. stderr_logfile_backups=10
  304. stderr_capturefile=NONE
  305. environment=A=1,B=2
  306. '[program:foo]' -- the section header, required for each program.
  307. 'programname' is a descriptive name (arbitrary) used to describe the
  308. program being run. It must not include a colon character or a
  309. bracket character.
  310. 'command' -- the command that will be run when this program is
  311. started. The command can be either absolute,
  312. e.g. ('/path/to/programname') or relative ('programname'). If it is
  313. relative, the PATH will be searched for the executable. Programs
  314. can accept arguments, e.g. ('/path/to/program foo bar'). The
  315. command line can used double quotes to group arguments with spaces
  316. in them to pass to the program, e.g. ('/path/to/program/name -p "foo
  317. bar"'). Note that the value of 'command' may include Python string
  318. expressions, e.g. "/path/to/programname --port=80%(process_num)02d"
  319. might expand to "/path/to/programname --port=8000" at runtime.
  320. String expressions are evaluated against a dictionary containing the
  321. keys "group_name", "process_num" and "program_name". **Controlled
  322. programs should themselves not be daemons, as supervisord assumes it
  323. is responsible for daemonizing its subprocesses (see "Nondaemonizing
  324. of Subprocesses" later in this document).**
  325. 'process_name' -- a Python string expression that is used to compose
  326. the supervisor process name for this process. You usually don't
  327. need to worry about setting this unless you change 'numprocs'. The
  328. string expression is evaluated against a dictionary that includes
  329. "group_name", "process_num" and "program_name". Default:
  330. %(program_name)s. (New in 3.0)
  331. 'numprocs' -- Supervisor will start as many instances of this
  332. program as named by numprocs. Note that if numprocs > 1, the
  333. 'process_name' expression must include '%(process_num)s' (or any
  334. other valid Python string expression that includes 'process_num')
  335. within it. Default: 1. (New in 3.0)
  336. 'priority' -- the relative priority of the program in the start and
  337. shutdown ordering. Lower priorities indicate programs that start
  338. first and shut down last at startup and when aggregate commands are
  339. used in various clients (e.g. "start all"/"stop all"). Higher
  340. priorities indicate programs that start last and shut down first.
  341. Default: 999.
  342. 'autostart' -- If true, this program will start automatically when
  343. supervisord is started. Default: true.
  344. 'autorestart' -- May be one of 'false', 'unexpected', or 'true'. If
  345. 'false', the process will never be autorestarted. If 'unexpected',
  346. the process will be restart when the program exits with an exit code
  347. that is not one of the exit codes associated with this process'
  348. configuration (see 'exitcodes'). If 'true, the process will be
  349. unconditionally restarted when it exits, without regard to its exit
  350. code. Default: unexpected.
  351. 'startsecs' -- The total number of seconds which the program needs
  352. to stay running after a startup to consider the start successful.
  353. If the program does not stay up for this many seconds after it is
  354. started, even if it exits with an "expected" exit code (see
  355. "exitcodes"), the startup will be considered a failure. Set to 0
  356. to indicate that the program needn't stay running for any particular
  357. amount of time. Default: 1
  358. 'startretries' -- The number of serial failure attempts that
  359. supervisord will allow when attempting to start the program before
  360. giving up and puting the process into an ERROR state. Default: 3.
  361. 'exitcodes' -- The list of 'expected' exit codes for this program.
  362. If the 'autorestart' parameter is set to 'unexpected', and the
  363. process exits in any other way than as a result of a supervisor stop
  364. request, supervisor will restart the process if it exits with an
  365. exit code that is not defined in this list. Default: 0,2.
  366. 'stopsignal' -- The signal used to kill the program when a stop is
  367. requested. This can be any of TERM, HUP, INT, QUIT, KILL, USR1, or
  368. USR2. Default: TERM.
  369. 'stopwaitsecs' -- The number of seconds to wait for the program to
  370. return a SIGCHILD to supervisord after the program has been sent a
  371. stopsignal. If this number of seconds elapses before supervisord
  372. receives a SIGCHILD from the process, supervisord will attempt to
  373. kill it with a final SIGKILL. Default: 10.
  374. 'user' -- If supervisord is running as root, this UNIX user account
  375. will be used as the account which runs the program. If supervisord
  376. is not running as root, this option has no effect. Default: do not
  377. switch users.
  378. 'redirect_stderr' -- If true, cause the process' stderr output to be
  379. sent back to supervisor on it's stdout file descriptor (in UNIX
  380. shell terms, this is the equivalent of executing "/the/program
  381. 2>&1". Default: false. (New in 3.0, replaces 2.0's "log_stdout" and
  382. "log_stderr")
  383. 'stdout_logfile' -- Put process stdout output in this file (and if
  384. redirect_stderr is true, also place stderr output in this file). If
  385. 'stdout_logfile' is unset or set to 'AUTO', supervisor will
  386. automatically choose a file location. If this is set to 'NONE',
  387. supervisord will create no log file. AUTO log files and their
  388. backups will be deleted when supervisord restarts. The
  389. stdout_logfile value can contain Python string expressions that will
  390. evaluated against a dictionary that contains the keys "process_num",
  391. "program_name" and "group_name". Default: AUTO. (New in 3.0,
  392. replaces 2.0's "logfile")
  393. 'stdout_logfile_maxbytes' -- The maximum number of bytes that may be
  394. consumed by stdout_logfile before it is rotated (suffix multipliers
  395. like "KB", "MB", and "GB" can be used in the value). Set this value
  396. to 0 to indicate an unlimited log size. Default: 50MB. (New in
  397. 3.0, replaces 2.0's "logfile_maxbytes")
  398. 'stdout_logfile_backups' -- The number of stdout_logfile backups to
  399. keep around resulting from process stdout log file rotation. Set
  400. this to 0 to indicate an unlimited number of backups. Default: 10.
  401. (New in 3.0, replaces "logfile_backups")
  402. 'stdout_capturefile' -- file written to when process is in "stdout
  403. capture mode" (see "Capture Mode and Process Communication Events"
  404. later in this document). May be a file path, NONE, or AUTO. The
  405. stdout_capturefile value can contain Python string expressions that
  406. will evaluated against a dictionary that contains the keys
  407. "process_num", "program_name" and "group_name". Default: NONE.
  408. (New in 3.0)
  409. 'stderr_logfile' -- Put process stderr output in this file unless
  410. redirect_stderr is true. Accepts the same value types as
  411. "stdout_logfile" and may contain the same Python string expressions.
  412. Default: AUTO. (New in 3.0)
  413. 'stderr_logfile_maxbytes' -- The maximum number of bytes before
  414. logfile rotation for stderr_logfile. Accepts the same value types
  415. as "stdout_logfile_maxbytes". Default: 50MB. (New in 3.0)
  416. 'stderr_logfile_backups' -- The number of backups to keep around
  417. resulting from process stderr log file rotation. Default: 10. (New
  418. in 3.0)
  419. 'stderr_capturefile' -- file written to when process is in "stderr
  420. capture mode" (see "Capture Mode and Process Communication Events"
  421. later in this document). May contain the same Python string
  422. expressions as "stdout_capturefile". May be a file path, NONE, or
  423. AUTO. Default: NONE. (New in 3.0)
  424. 'environment' -- A list of key/value pairs in the form
  425. "KEY=val,KEY2=val2" that will be placed in the child process'
  426. environment. The environment string may contain Python string
  427. expressions that will be evaluated against a dictionary containing
  428. "process_num", "program_name" and "group_name". Default: none.
  429. **Note** that the subprocess will inherit the environment variables
  430. of the shell used to start "supervisord" except for the ones
  431. overridden here. See "Subprocess Environment" below.
  432. Note that a '[program:x]' section actually represents a "homogeneous
  433. process group" to supervisor (new in 3.0). The members of the group
  434. are defined by the combination of the 'numprocs and 'process_name'
  435. parameters in the configuration. By default, if numprocs and
  436. process_name are left unchanged from their defaults, the group
  437. represented by '[program:x]' will be named 'x' and will have a
  438. single process named 'x' in it. This provides a modicum of
  439. backwards compatibility with older supervisor releases, which did
  440. not treat program sections as homogeneous process group defnitions.
  441. But for instance, if you have a '[program:foo]' section with a
  442. 'numprocs' of 3 and a 'process_name' expression of
  443. '%(program_name)s_%(process_num)02d', the "foo" group will contain
  444. three processes, named 'foo_00', 'foo_01', and 'foo_02'. This makes
  445. it possible to start a number of very similar processes using a
  446. single '[program:x]' section. All logfile names, all environment
  447. strings, and the command of programs can also contain similar Python
  448. string expressions, to pass slightly different parameters to each
  449. process.
  450. Configuration File '[group:x]' Section Settings (New in 3.0)
  451. It is often useful to group "homogeneous" processes groups (aka
  452. "programs") together into a "heterogeneous" process group so they
  453. can be controlled as a unit from supervisor's various controller
  454. interfaces.
  455. To place programs into a group so you can treat them as a unit,
  456. define a '[group:x]' section in your configuration file, e.g.::
  457. [group:foo]
  458. programs=bar,baz
  459. priority=999
  460. For the example above to work, there must be two 'program' sections
  461. elsewhere in your configuration file: '[program:bar]' and
  462. '[program:baz]'. If "homogeneous" program groups" (represented by
  463. program sections) are placed into a "heterogeneous" group via
  464. '[group:x]' section's "programs=" line, the homogeneous groups that
  465. are implied by the program section will not exist at runtime in
  466. supervisor. Instead, all processes belonging to each of the
  467. homogeneous groups will be placed into the heterogeneous group. In
  468. the above example, it means that the 'bar' and 'baz' homogeneous
  469. groups will not exist, and the processes that would have been under
  470. them will now be moved into the 'foo' group.
  471. Configuration File '[eventlistener:x]' Section Settings (New in 3.0)
  472. Supervisor allows specialized homogeneous process groups ("event
  473. listener pools") to be defined within the configuration file. These
  474. pools contain processes that are meant to receive and respond to
  475. event notifications from supervisor's event system. See "Supervisor
  476. Events" elsewhere in this document for an explanation of how events
  477. work and how to implement event listener programs.
  478. An example of an eventlistener section defined within a supervisor
  479. configuration file, which creates a pool::
  480. [eventlistener:theeventlistenername]
  481. command=/bin/eventlistener
  482. process_name=%(program_name)s_%(process_num)02d
  483. numprocs=5
  484. events=PROCESS_STATE_CHANGE
  485. buffer_size=10
  486. priority=-1
  487. autostart=true
  488. autorestart=unexpected
  489. startsecs=1
  490. startretries=3
  491. exitcodes=0,2
  492. stopsignal=QUIT
  493. stopwaitsecs=10
  494. user=chrism
  495. redirect_stderr=true
  496. stdout_logfile=/a/path
  497. stdout_logfile_maxbytes=1MB
  498. stdout_logfile_backups=10
  499. stderr_logfile=/a/path
  500. stderr_logfile_maxbytes=1MB
  501. stderr_logfile_backups
  502. environment=A=1,B=2
  503. Note that all the options available to '[program:x]' sections are
  504. respected by eventlistener sections except for "stdout_capturefile"
  505. and "stderr_capturefile" (event listeners cannot emit process
  506. communication events, see "Capture Mode and Process Communication
  507. Events" elsewhere in this document).
  508. '[eventlistener:x]' sections have two keys which '[program:x]'
  509. sections do not have:
  510. 'buffer_size' -- The event listener pool's event queue buffer size.
  511. When a listener pool's event buffer is overflowed (as can happen
  512. when an event listener pool cannot keep up with all of the events
  513. sent to it), the oldest event in the buffer is discarded.
  514. 'events' -- A comma-separated list of event type names that this
  515. listener is "interested" in receiving notifications for (see
  516. "Supervisor Events" elsewhere in this document for a list of valid
  517. event type names).
  518. Configuration File '[rpcinterface:x]' Section Settings (ADVANCED, New in 3.0)
  519. Changing "rpcinterface:x" settings in the configuration file is only
  520. useful for people who wish to extend supervisor with additional
  521. behavior.
  522. In the sample config file, there is a section which is named
  523. "rpcinterface:supervisor". By default it looks like this::
  524. [rpcinterface:supervisor]
  525. supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
  526. This section *must* remain in the configuration for the standard
  527. setup of supervisor to work properly. If you don't want supervisor
  528. to do anything it doesn't already do out of the box, this is all you
  529. need to know about this type of section.
  530. However, if you wish to add rpc interface namespaces to a custom
  531. version of supervisor, you may add additional [rpcinterface:foo]
  532. sections, where "foo" represents the namespace of the interface
  533. (from the web root), and the value named by
  534. "supervisor.rpcinterface_factory" is a factory callable which should
  535. have a function signature that accepts a single positional argument
  536. "supervisord" and as many keyword arguments as required to perform
  537. configuration. Any key/value pairs defined within the
  538. rpcinterface:foo section will be passed as keyword arguments to the
  539. factory. Here's an example of a factory function, created in the
  540. package "my.package"::
  541. def make_another_rpcinterface(supervisord, **config):
  542. retries = int(config.get('retries', 0))
  543. another_rpc_interface = AnotherRPCInterface(supervisord, retries)
  544. return another_rpc_interface
  545. And a section in the config file meant to configure
  546. it::
  547. [rpcinterface:another]
  548. supervisor.rpcinterface_factory = my.package:make_another_rpcinterface
  549. retries = 1
  550. Nondaemonizing of Subprocesses
  551. Programs run under supervisor *should not* daemonize themselves.
  552. Instead, they should run in the foreground and not detach from the
  553. "terminal" that starts them. The easiest way to tell if a command
  554. will run in the foreground is to run the command from a shell
  555. prompt. If it gives you control of the terminal back, it's
  556. daemonizing itself and that will be the wrong way to run it under
  557. supervisor. You want to run a command that essentially requires you
  558. to press Ctrl-C to get control of the terminal back. If it gives
  559. you a shell prompt back after running it without needing to press
  560. Ctrl-C, it's not useful under supervisor. All programs have options
  561. to be run in the foreground but there's no standard way to do it;
  562. you'll need to read the documentation for each program you want to
  563. do this with.
  564. Subprocess Environment
  565. Subprocesses will inherit the environment of the shell used to start
  566. the supervisord program. Several environment variables will be set
  567. by supervisor itself in the child's environment also, including
  568. "SUPERVISOR_ENABLED" (a flag indicating the process is under
  569. supervisor control), "SUPERVISOR_PROCESS_NAME" (the
  570. config-file-specified process name for this process) and
  571. "SUPERVISOR_GROUP_NAME" (the config-file-specified process group name
  572. for the child process).
  573. These environment variables may be overridden within the
  574. "environment" global config option (applies to all subprocesses) or
  575. within the per-program "environment" config option (applies only to
  576. the subprocess specified within the "program" section). These
  577. "environment" settings are additive. In other words, each
  578. subprocess' environment will consist of::
  579. The environment variables set within the shell used to start
  580. supervisord...
  581. ... added-to/overridden-by ...
  582. ... the environment variables set within the "environment" global
  583. config option ...
  584. ... added-to/overridden-by ...
  585. ... supervisor-specific environment variables
  586. ("SUPERVISOR_ENABLED", "SUPERVISOR_PROCESS_NAME",
  587. "SUPERVISOR_GROUP_NAME") .. (New in 3.0)
  588. ... added-to/overridden-by ...
  589. .. the environment variables set within the per-process
  590. "environment" config option.
  591. No shell is executed by supervisord when it runs a subprocess, so
  592. settings such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not
  593. changed from their defaults or otherwise reassigned. This is
  594. particularly important to note when you are running a program from a
  595. supervisord run as root with a "user=" stanza in the configuration.
  596. Unlike cron, supervisord does not attempt to divine and override
  597. "fundamental" environment variables like USER, PATH, HOME, and
  598. LOGNAME when it performs a setuid to the user defined within the
  599. "user=" program config option. If you need to set environment
  600. variables for a particular program that might otherwise be set by a
  601. shell invocation for a particular user, you must do it explicitly
  602. within the "environment=" program config option. For example::
  603. [program:apache]
  604. command=/home/chrism/bin/httpd -DNO_DETACH
  605. user=chrism
  606. environment=HOME=/home/chrism,USER=chrism
  607. Examples of Program Configurations
  608. Apache 2.0.54::
  609. [program:apache]
  610. command=/usr/sbin/httpd -DNO_DETACH
  611. Postgres 8.14::
  612. [program:postgres]
  613. command=/path/to/postmaster
  614. ; we use the "fast" shutdown signal SIGINT
  615. stopsignal=INT
  616. redirect_stderr=true
  617. Zope 2.8 instances and ZEO::
  618. [program:zeo]
  619. command=/path/to/runzeo
  620. priority=1
  621. [program:zope1]
  622. command=/path/to/instance/home/bin/runzope
  623. priority=2
  624. redirect_stderr=true
  625. [program:zope2]
  626. command=/path/to/another/instance/home/bin/runzope
  627. priority=2
  628. redirect_stderr=true
  629. OpenLDAP slapd::
  630. [program:slapd]
  631. command=/path/to/slapd -f /path/to/slapd.conf -h ldap://0.0.0.0:8888
  632. Process States
  633. A process controlled by supervisord will be in one of the below
  634. states at any given time. You may see these state names in various
  635. user interface elements.
  636. STOPPED (0) -- The process has been stopped due to a stop request or
  637. has never been started.
  638. STARTING (10) -- The process is starting due to a start request.
  639. RUNNING (20) -- The process is running.
  640. BACKOFF (30) -- The process entered the STARTING state but
  641. subsequently exited too quickly to move to the
  642. RUNNING state.
  643. STOPPING (40) -- The process is stopping due to a stop request.
  644. EXITED (100) -- The process exited from the RUNNING state (expectedly
  645. or unexpectedly).
  646. FATAL (200) -- The process could not be started successfully.
  647. UNKNOWN (1000) -- The process is in an unknown state (programming error).
  648. Process progress through these states as per the following directed
  649. graph::
  650. --> STOPPED
  651. / |
  652. | |
  653. | |
  654. STOPPING |
  655. ^ ^ V
  656. | \--- STARTING <-----> BACKOFF
  657. | / ^ |
  658. | V | |
  659. \-- RUNNING / \ |
  660. | / \ V
  661. V / \ ----- FATAL
  662. EXITED
  663. A process is in the STOPPED state if it has been stopped
  664. adminstratively or if it has never been started.
  665. When an autorestarting process is in the BACKOFF state, it will be
  666. automatically restarted by supervisord. It will switch between
  667. STARTING and BACKOFF states until it becomes evident that it cannot
  668. be started because the number of startretries has exceeded the
  669. maximum, at which point it will transition to the FATAL state. Each
  670. start retry will take progressively more time.
  671. When a process is in the EXITED state, it will automatically
  672. restart:
  673. - never if its 'autorestart' parameter is set to 'false'.
  674. - unconditionally if its 'autorestart' parameter is set to
  675. 'true'.
  676. - conditionally if its 'autorestart' parameter is set to
  677. 'unexpected'. If it exited with an exit code that doesn't match
  678. one of the exit codes defined in the 'exitcodes' configuration
  679. parameter for the process, it will be restarted.
  680. A process automatically transitions from EXITED to RUNNING as a
  681. result of being configured to autorestart conditionally or
  682. unconditionally. The number of transitions between RUNNING and
  683. EXITED is not limited in any way: it is possible to create a
  684. configuration that endlessly restarts an exited process.
  685. An autorestarted process will never be automtatically restarted if
  686. it ends up in the FATAL state (it must be manually restarted from
  687. this state).
  688. A process transitions into the STOPPING state via an administrative
  689. stop request, and will then end up in the STOPPED state.
  690. A process that cannot be stopped successfully will stay in the
  691. STOPPING state forever. This situation should never be reached
  692. during normal operations as it implies that the process did not
  693. respond to a final SIGKILL, which is "impossible" under UNIX.
  694. State transitions which always require user action to invoke are
  695. these:
  696. FATAL -> STARTING
  697. RUNNING -> STOPPING
  698. State transitions which typically, but not always, require user
  699. action to invoke are these, with exceptions noted:
  700. STOPPED -> STARTING (except at supervisord startup if process is
  701. configured to autostart)
  702. EXITED -> STARTING (except if process is configured to autorestart)
  703. All other state transitions are managed by supervisord
  704. automatically.
  705. Supervisor Events (New in 3.0)
  706. At certain predefined points during supervisord's operation, "event
  707. notifications" are emitted. An event notification implies that
  708. something potentially interesting happened. Event listeners (see
  709. the "Event Listeners" section below) can be configured to subscribe
  710. to event notifications selectively, and may perform arbitrary
  711. actions based on an event notification (send email, make an HTTP
  712. request, etc).
  713. Event types that may be subscribed to by event listeners are
  714. predefined by supervisor and fall into several major categories,
  715. including "process state change", "process communication",
  716. "supervisor state change", and "event system meta" events. These
  717. are described in detail below.
  718. EVENT -- The base event type. This event type is abstract. It will
  719. never be sent directly. Subscribing to this event type will cause a
  720. subscriber to receive all event notifications emitted by supervisor.
  721. Subtypes of EVENT:
  722. PROCESS_STATE_CHANGE -- The value of this event type will be the
  723. process name. This event type is abstract, it will never be sent
  724. directly. Subscribing to this event type will cause a subscriber
  725. to receive event notifications of all the types listed below in
  726. "Subtypes of PROCESS_STATE_CHANGE".
  727. The serialized body of a PROCESS_STATE_CHANGE event (and all
  728. subtypes) is in the form::
  729. process_name: <name>
  730. group_name: <name>
  731. Subtypes of PROCESS_STATE_CHANGE:
  732. PROCESS_STATE_CHANGE_STARTING -- indicates a process has moved
  733. from a state to the STARTING state. Subscribing to this event
  734. type will cause a subscriber to receive event notifications of
  735. all the types listed below in "Subtypes of
  736. PROCESS_STATE_CHANGE_STARTING".
  737. Subtypes of PROCESS_STATE_CHANGE_STARTING:
  738. PROCESS_STATE_CHANGE_STARTING_FROM_STOPPED -- subtype of
  739. PROCESS_STATE_CHANGE_STARTING, indicates a process has moved
  740. from the STOPPED state from the STARTING state.
  741. PROCESS_STATE_CHANGE_STARTING_FROM_BACKOFF -- subtype of
  742. PROCESS_STATE_CHANGE_STARTING, indicates a process has moved
  743. from BACKOFF state to the STARTING state.
  744. PROCESS_STATE_CHANGE_STARTING_FROM_EXITED -- subtype of
  745. PROCESS_STATE_CHANGE_STARTING, indicates a process has moved
  746. from the EXITED state to the STARTING state.
  747. PROCESS_STATE_CHANGE_STARTING_FROM_FATAL -- subtype of
  748. PROCESS_STATE_CHANGE_STARTING, indicates a process has moved
  749. to the FATAL state to the STARTING state.
  750. PROCESS_STATE_CHANGE_RUNNING_FROM_STARTING -- inidicates a
  751. process has moved from the STARTING state to the RUNNING state.
  752. PROCESS_STATE_CHANGE_BACKOFF_FROM_STARTING -- indicates a
  753. process has moved from the STARTING state to the BACKOFF state.
  754. PROCESS_STATE_CHANGE_STOPPING_FROM_RUNNING -- indicates a
  755. process has moved from the RUNNING state to the STOPPING state.
  756. PROCESS_STATE_CHANGE_STOPPING_FROM_STARTING -- indicates a
  757. process has moved from the RUNNING state to the STARTING state.
  758. PROCESS_STATE_CHANGE_EXITED_OR_STOPPED -- indicates a process
  759. has undergone a state change which caused it to move to the
  760. EXITED or STOPPED state.
  761. Subtypes of PROCESS_STATE_CHANGE_EXITED_OR_STOPPED:
  762. PROCESS_STATE_CHANGE_EXITED_FROM_RUNNNING -- indicates a
  763. process has moved from the RUNNING state to the EXITED state.
  764. PROCESS_STATE_CHANGE_STOPPED_FROM_STOPPING -- indicates a
  765. process has moved from the STOPPING state to the STOPPED
  766. state.
  767. PROCESS_STATE_CHANGE_FATAL_FROM_BACKOFF -- indicates a process
  768. has moved from the BACKOFF state to the FATAL state.
  769. PROCESS_STATE_CHANGE_TO_UNKNOWN -- indicates a process has moved
  770. from a state to the UNKNOWN state (indicates an error in
  771. supervisord).
  772. PROCESS_COMMUNICATION -- an event type raised when any process
  773. attempts to send information between <!--XSUPERVISOR:BEGIN--> and
  774. <!--XSUPERVISOR:END--> tags in its output. This event type is
  775. abstract, it will never be sent directly. Subscribing to this
  776. event type will cause a subscriber to receive event notifications
  777. of all the types listed below in "Subtypes of
  778. PROCESS_COMMUNICATION".
  779. The serialized body of a PROCESS_COMMUNICATION event (and all
  780. subtypes) is::
  781. process_name: <name>
  782. group_name: <name>
  783. <data>
  784. Subtypes of PROCESS_COMMUNICATION:
  785. PROCESS_COMMUNICATION_STDOUT -- indicates a process has sent a
  786. message to supervisor on its stdout file descriptor.
  787. PROCESS_COMMUNICATION_STDERR -- indicates a process has sent a
  788. message to supervisor on its stderr file descriptor.
  789. SUPERVISOR_STATE_CHANGE -- an event type raised when supervisor's
  790. state changes. There is no value. Subscribing to this event type
  791. will cause a subscriber to receive event notifications of all the
  792. types listed below in "Subtypes of SUPERVISOR_STATE_CHANGE".
  793. The serialization of a SUPERVISOR_STATE_CHANGE event is the empty
  794. string.
  795. Subtypes of SUPERVISOR_STATE_CHANGE:
  796. SUPERVISOR_STATE_CHANGE_RUNNING -- indicates that supervisor has
  797. started.
  798. SUPERVISOR_STATE_CHANGE_STOPPING -- indicates that supervisor is
  799. stopping or restarting.
  800. EVENT_BUFFER_OVERFLOW -- an event type raised when a listener
  801. pool's event buffer is overflowed (as can happen when an event
  802. listener pool cannot keep up with all of the events sent to it).
  803. When the pool's event buffer is overflowed, the oldest event in
  804. the buffer is thrown out.
  805. The serialization of an EVENT_BUFFER_OVERFLOW body
  806. is::
  807. group_name: <name>
  808. event_type: <type of discarded event>
  809. Event Listeners (New in 3.0)
  810. Supervisor event listeners are subprocesses which are treated almost
  811. exactly like supervisor "programs" with the following differences:
  812. - They are defined using an [eventlistener:x] section in the config
  813. file instead of a [program:x] section in the configuration file.
  814. - Supervisor sends specially-formatted input to an event listener's
  815. stdin and expects specially-formatted output from an event
  816. listener's stdout in a request-response cycle. A protocol agreed
  817. upon between supervisor and the listener's implementer allows
  818. listeners to process event notifications.
  819. - Supervisor does not respect "capture mode" output from event
  820. listener processes (see "Capture Mode and Process Communication
  821. Events" elsewhere in this document).
  822. When an [eventlistener:x] section is defined, it actually defines a
  823. "pool", where the number of event listeners in the pool is
  824. determined by the "numprocs" value within the section. Every
  825. process in the event listener pool is treated equally by supervisor,
  826. and supervisor will choose one process from the pool to receive
  827. event notifications (filtered by the "events=" key in the
  828. eventlistener section).
  829. An event listener can send arbitrary output to its stderr, which
  830. will be logged or ignored by supervisord depending on the
  831. stderr-related configuration files in its [eventlistener:x] section.
  832. When an event notification is sent by the supervisor, all event
  833. listener pools which are subscribed to receive events for the
  834. event's type will be found. One of the listeners in each listener
  835. pool will receive the event notification (any "available" listener).
  836. If the event cannot be sent because all listener in a pool are
  837. "busy", the event will be buffered and notification will be retried
  838. later. "Later" is defined as "the next time that supervisord's
  839. select loop executes".
  840. A listener pool has an event buffer queue. The queue is sized via
  841. the listener pool's "buffer_size" config file option. If the queue
  842. is full and supervisor attempts to buffer an event, supervisor will
  843. throw away the oldest event in the buffer, log an error, and send an
  844. EVENT_BUFFER_OVERFLOW event. EVENT_BUFFER_OVERFLOW events are never
  845. themselves buffered.
  846. Event listeners can be implemented in any language. Event listeners
  847. can be long-running or may exit after a single request (depending on
  848. the implementation and the "autorestart" parameter in the
  849. eventlistener's configuration).
  850. An event listener implementation should operate in "unbuffered" mode
  851. or should flush its stdout every time it needs to communicate back
  852. to the supervisord process.
  853. Event Listener States
  854. An event listener process has three possible states that are
  855. maintained by supervisord:
  856. ACKNOWLEDGED -- The event listener has acknowledged (accepted or
  857. rejected) an event send.
  858. READY -- Event notifications may be sent to this event listener.
  859. BUSY -- Event notifications may not be sent to this event
  860. listener.
  861. When an event listener process first starts, supervisor
  862. automatically places it into the ACKNOWLEDGED state to allow for
  863. startup activities or guard against startup failures (hangs). Until
  864. the listener sends a READY token to its stdout, it will stay in this
  865. state.
  866. When supervisord sends an event notification to a listener in the
  867. READY state, the listener will be placed into the BUSY state until
  868. it receives an OK or FAILED response from the listener, at which
  869. time, the listener will be transitioned back into the ACKNOWLEDGED
  870. state.
  871. Event Listener Notification Protocol
  872. Supervisord will notify an event listener in the READY state of an
  873. event by sending data to the stdin of the process. Supervisord will
  874. never send anything to the stdin of an event listener process while
  875. that process is in the BUSY or ACKNOWLEDGED state.
  876. When supervisord sends a notification to an event listener process,
  877. the listener will first be sent a single "header" line on its
  878. stdin. The composition of the line is a set of four tokens separated
  879. by single spaces. The line is terminated with a '\n' (linefeed)
  880. character. The tokens on the line are:
  881. <PROTOCOL_VERSION> <EVENT_TYPE_NAME> <EVENT_SERIAL_NUM> <PAYLOAD_LENGTH>
  882. The PROTOCOL_VERSION always consists of "SUPERVISORD" followed
  883. immediately by numeric characters indicating the protocol version,
  884. with no whitespace in between. An example: "SUPERVISOR3.0"
  885. The EVENT_TYPE_NAME is the specific event type name (see "Supervisor
  886. Events" elsewhere in this document). An example:
  887. "PROCESS_COMMUNICATION_STDOUT".
  888. The EVENT_SERIAL_NUM is an integer assigned to each event. It is
  889. useful for functional testing. An example: "30".
  890. The PAYLOAD_LENGTH is an integer indicating the number of bytes in
  891. the event payload. An example: "22".
  892. An example of a complete header line:
  893. SUPERVISOR3.0 PROCESS_COMMUNICATION_STDOUT 30 22\n
  894. Directly following the linefeed character in the header is the event
  895. payload. It consists of PAYLOAD_LENGTH bytes representing a
  896. serialization of the event data. See "Supervisor Events" for the
  897. specific event data serialization definitions. An example payload
  898. for a PROCESS_COMMUNICATION_STDOUT event notification is::
  899. process_name: foo
  900. group_name: bar
  901. This is the data that was sent between the tags
  902. Once it has processed the header, the event listener implementation
  903. should read PAYLOAD_LENGTH bytes from its stdin, perform an
  904. arbitrary action based on the values in the header and the data
  905. parsed out of the serialization. It is free to block for an
  906. arbitrary amount of time while doing this. Supervisor will continue
  907. processing normally as it waits for a response and it will send
  908. other events of the same type to other listener processes in the
  909. same pool as necessary.
  910. After the event listener has processed the event serialization, in
  911. order to notify supervisord about the result, it should send either
  912. an "OK" token or a "FAILED" token immediately followed by a carriage
  913. return character to its stdout. If supervisord receives an "OK"
  914. token, it will assume that the listener processed the event
  915. notification successfully. If it receives a "FAILED" token, it will
  916. assume that the listener has failed to process the event, and the
  917. event will be rebuffered and sent again at a later time. The event
  918. listener may reject the event for any reason by returning a "FAILED"
  919. token. This does not indicate a problem with the event data or the
  920. event listener. Once an "OK" or "FAILED" token is received by
  921. supervisord, the event listener is placed into the ACKNOWLEDGED
  922. state.
  923. Once the listener is in the ACKNOWLEDGED state, it may either exit
  924. (and subsequently may be restarted by supervisor if its
  925. "autorestart" config parameter is 'true'), or it may continue
  926. running. If it continues to run, in order to be placed back into
  927. the READY state by supervisord, it must send a "READY" token
  928. followed immediately by a carriage return to its stdout.
  929. Example Event Listener Implementation
  930. A Python implementation of a "long-running" event listener which
  931. accepts an event notification, prints the header and a list of event
  932. serial numbers it has received to its stderr, and responds with an
  933. OK, and then subsequently a READY is as follows::
  934. import sys
  935. L = []
  936. def stdout_write(s):
  937. sys.stdout.write(s)
  938. sys.stdout.flush()
  939. def stderr_write(s):
  940. sys.stderr.write(s)
  941. sys.stderr.flush()
  942. while 1:
  943. stdout_write('READY\n')
  944. line = sys.stdin.readline()
  945. stderr_write(line)
  946. ver, event, serial, length = line.split(' ', 3)
  947. L.append(serial)
  948. data = sys.stdin.read(int(length))
  949. stderr_write(str(L))
  950. stdout_write('OK\n')
  951. Event Listener Error Conditions
  952. If the event listener process dies while the event is being
  953. transmitted to its stdin, or if it dies before sending an OK/FAILED
  954. response back to supervisord, the event is assumed to not be
  955. processed and will be rebuffered by supervisord and sent again
  956. later.
  957. If an event listener sends data to its stdout which supervisor does
  958. not recognize as an appropriate response based on the state that the
  959. event listener is in, the event listener will be placed into the
  960. UNKNOWN state, and no further event notifications will be sent to
  961. it. If an event was being processed by the listener during this
  962. time, it will be rebuffered and sent again later.
  963. Capture Mode and Process Communication Events (New in 3.0)
  964. If a '[program:x]' section in the configuration file defines a
  965. "stdout_capturefile" or "stderr_capturefile" parameter, each process
  966. represented by the program section may emit special tokens on its
  967. stdout or stderr stream (respectively) which will effectively cause
  968. supervisor to emit a "PROCESS_COMMUNICATION" event type.
  969. The process communications protocol relies on two tags, one which
  970. commands supervisor to enter "capture mode" for the stream and one
  971. which commands it to exit. When a process stream enters "capture
  972. mode", data sent to the stream will be sent to a separate logfile
  973. (the "capturefile"). When a process stream exits capture mode, the
  974. data in the capturefile is read into memory (a maximum of 2MB), and
  975. a PROCESS_COMMUNICATION event is emitted by supervisor, which may be
  976. intercepted by event listeners.
  977. The tag to begin "capture mode" in a process stream is
  978. '<!--XSUPERVISOR:BEGIN-->'. The tag to exit capture mode is
  979. '<!--XSUPERVISOR:END-->'. The data between these tags may be
  980. arbitrary, and forms the payload of the PROCESS_COMMUNICATION event.
  981. For example, if a program is set up with a stdout_capturefile, and
  982. it emits the following on its stdout stream::
  983. <!--XSUPERVISOR:BEGIN-->Hello!<!--XSUPERVISOR:END-->
  984. .. supervisor will emit a PROCESS_COMMUNICATIONS_STDOUT event with
  985. data in the payload of "Hello!".
  986. Signals
  987. Killing supervisord with SIGHUP will stop all processes, reload the
  988. configuration from the config file, and restart all processes.
  989. Killing supervisord with SIGUSR2 will close and reopen the
  990. supervisord activity log and child log files.
  991. Access Control
  992. The UNIX permissions on the socket effectively control who may send
  993. commands to the server. HTTP basic authentication provides access
  994. control for internet and UNIX domain sockets as necessary.
  995. Security Notes
  996. I have done my best to assure that use of a supervisord process
  997. running as root cannot lead to unintended privilege escalation, but
  998. caveat emptor. Particularly, it is not as paranoid as something
  999. like DJ Bernstein's "daemontools", inasmuch as "supervisord" allows
  1000. for arbitrary path specifications in its configuration file to which
  1001. data may be written. Allowing arbitrary path selections can create
  1002. vulnerabilities from symlink attacks. Be careful when specifying
  1003. paths in your configuration. Ensure that supervisord's
  1004. configuration file cannot be read from or written to by unprivileged
  1005. users and that all files installed by the supervisor package have
  1006. "sane" file permission protection settings. Additionally, ensure
  1007. that your PYTHONPATH is sane and that all Python standard library
  1008. files have adequate file permission protections. Then, pray to the
  1009. deity of your choice.
  1010. Other Notes
  1011. Some examples of shell scripts to start services under supervisor
  1012. can be found "here":http://www.thedjbway.org/services.html. These
  1013. examples are actually for daemontools but the premise is the same
  1014. for supervisor. Another collection of recipes for starting various
  1015. programs in the foreground is
  1016. "here":http://smarden.org/runit/runscripts.html .
  1017. Some processes (like mysqld) ignore signals sent to the actual
  1018. process/thread which is created by supervisord. Instead, a
  1019. "special" thread/process is created by these kinds of programs which
  1020. is responsible for handling signals. This is problematic, because
  1021. supervisord can only kill a pid which it creates itself, not any
  1022. child thread or process of the program it creates. Fortunately,
  1023. these programs typically write a pidfile which is meant to be read
  1024. in order to kill the process. As a workaround for this case, a
  1025. special "pidproxy" program can handle startup of these kinds of
  1026. processes. The pidproxy program is a small shim that starts a
  1027. process, and upon the receipt of a signal, sends the signal to the
  1028. pid provided in a pidfile. A sample supervisord configuration
  1029. program entry for a pidproxy-enabled program is provided here::
  1030. [program:mysql]
  1031. command=/path/to/pidproxy /path/to/pidfile /path/to/mysqld_safe
  1032. The pidproxy program is named 'pidproxy.py' and is in the
  1033. supervisor distribution.
  1034. FAQ
  1035. My program never starts and supervisor doesn't indicate any error:
  1036. Make sure the "x" bit is set on the executable file you're using in
  1037. the command= line.
  1038. How can I tell if my program is running under supervisor? Supervisor
  1039. and its subprocesses share an environment variable
  1040. "SUPERVISOR_ENABLED". When a process is run under supervisor, your
  1041. program can check for the presence of this variable to determine
  1042. whether it is running under supervisor (new in 2.0).
  1043. My command line works fine when I invoke it by hand from a shell
  1044. prompt, but when I use the same command line in a supervisor
  1045. "command=" section, the program fails mysteriously. Why? This may
  1046. be due to your process' dependence on environment variable settings.
  1047. See "Subprocess Environment" in this document.
  1048. Maillist, Reporting Bugs, and Viewing the CVS Repository
  1049. You may subscribe to the 'Supervisor-users'
  1050. "maillist":http://lists.palladion.com/mailman/listinfo/supervisor-users
  1051. Please report bugs at "the
  1052. collector":http://www.plope.com/software/collector .
  1053. You can view the CVS repository for supervisor at
  1054. http://cvs.plope.com/viewcvs/Packages/supervisor2/
  1055. Contributing
  1056. If you'd like to contribute to supervisor, please contact me (Chris
  1057. McDonough, chrism@plope.com), and I'll arrange for you to have
  1058. direct CVS access to the repository.
  1059. Author Information
  1060. Chris McDonough (chrism@plope.com)
  1061. "Agendaless Consulting":http://www.agendaless.com