README.txt 59 KB

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