README.txt 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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.0
  7. Introduction
  8. The supervisor is a client/server system that allows its users to
  9. control a number of processes on UNIX-like operating systems. It
  10. was inspired by the following:
  11. - It is often inconvenient to need to write "rc.d" scripts for
  12. every single process instance. rc.d scripts are a great
  13. lowest-common-denominator form of process
  14. initialization/autostart/management, but they can be painful to
  15. write and maintain. Additionally, rc.d scripts cannot
  16. automatically restart a crashed process and many programs do not
  17. restart themselves properly on a crash. Supervisord starts
  18. processes as its subprocesses, and can be configured to
  19. automatically restart them on a crash. It can also automatically
  20. be configured to start processes on its own invocation.
  21. - It's often difficult to get accurate up/down status on processes
  22. on UNIX. Pidfiles often lie. Supervisord starts processes as
  23. subprocesses, so it always knows the true up/down status of its
  24. children and can be queried conveniently for this data.
  25. - Users who need to control process state often need only to do
  26. that. They don't want or need full-blown shell access to the
  27. machine on which the processes are running. Supervisorctl allows
  28. a very limited form of access to the machine, essentially
  29. allowing users to see process status and control
  30. supervisord-controlled subprocesses by emitting "stop", "start",
  31. and "restart" commands from a simple shell or web UI.
  32. - Users often need to control processes on many machines.
  33. Supervisor provides a simple, secure, and uniform mechanism for
  34. interactively and automatically controlling processes on groups
  35. of machines.
  36. - Processes which listen on "low" TCP ports often need to be
  37. started and restarted as the root user (a UNIX misfeature). It's
  38. usually the case that it's perfectly fine to allow "normal"
  39. people to stop or restart such a process, but providing them with
  40. shell access is often impractical, and providing them with root
  41. access or sudo access is often impossible. It's also (rightly)
  42. difficult to explain to them why this problem exists. If
  43. supervisord is started as root, it is possible to allow "normal"
  44. users to control such processes without needing to explain the
  45. intricacies of the problem to them.
  46. - Processes often need to be started and stopped in groups,
  47. sometimes even in a "priority order". It's often difficult to
  48. explain to people how to do this. Supervisor allows you to
  49. assign priorities to processes, and allows user to emit commands
  50. via the supervisorctl client like "start all", and "restart all",
  51. which starts them in the preassigned priority order.
  52. Supported Platforms
  53. Supervisor has been tested and is known to run on Linux (Fedora Core
  54. 5, Ubuntu 6), Mac OS X (10.4), and Solaris (10 for Intel) and
  55. FreeBSD 6.1. It will likely work fine on most UNIX systems.
  56. Supervisor will not run at all under any version of Windows.
  57. Supervisor requires Python 2.3 or better.
  58. Installing
  59. Run "python setup.py install". This will download and install all
  60. distributions depended upon by supervisor and finally install
  61. supervisor itself. Once that's done, copy the "sample.conf" file
  62. you'll find in the same directory as this file to
  63. /etc/supervisord.conf and modify to your liking. If you'd rather
  64. not put the supervisord.conf file in /etc, you can place it anywhere
  65. and start supervisord and point it at the configuration file via the
  66. -c flag, e.g. "python supervisord.py -c /path/to/sample/conf" or, if
  67. you use the shell script named "supervisord", "supervisord -c
  68. /path/to/sample.conf".
  69. I make reference below to a "$BINDIR" when explaining how to run
  70. supervisord and supervisorctl. This is the "bindir" directory that
  71. your Python installation has been configured with. For example, for
  72. an installation of Python installed via "./configure
  73. --prefix=/usr/local/python; make; make install", $BINDIR would be
  74. "/usr/local/python/bin". Python interpreters on different platforms
  75. use different $BINDIRs. Look at the output of "setup.py install" if
  76. you can't figure out where yours is.
  77. Installing Without Internet Access
  78. Since "setup.py install" performs downloads of dependent software,
  79. it will not work on machines without internet access. To install to
  80. a machine which is not internet connected, obtain the following
  81. dependencies on a machine which is internet-connected::
  82. - setuptools (latest) from http://pypi.python.org/pypi/setuptools
  83. - meld3 (0.6) from http://www.plope.com/software/meld3/
  84. - medusa (0.5.4) from http://www.amk.ca/python/code/medusa.html
  85. - elementtree (1.2.6) from http://effbot.org/downloads#elementtree
  86. And then copy these files to removable media and put them on the
  87. target machine. Install each onto the target machine as per its
  88. instructions.
  89. *Note* -- if the machine you're installing on does not have a C
  90. compiler, meld3's "setup.py install" probably won't work because
  91. meld3 uses C extensions, but you can either copy the meld3/meld3
  92. directory into your Python's site-packages directory, or you can
  93. build a binary distribution for your platform on a similar machine
  94. that does have a C compiler before shipping it over by doing "python
  95. setup.py bdist".
  96. Finally, run supervisor's "python setup.py install".
  97. Running Supervisord
  98. To start supervisord, run $BINDIR/supervisord. The resulting
  99. process will daemonize itself and detach from the terminal. It
  100. keeps an operations log at "/tmp/supervisor.log" by default.
  101. You can start supervisord in the foreground by passing the "-n" flag
  102. on its command line. This is useful to debug startup problems.
  103. To change the set of programs controlled by supervisord, edit the
  104. supervisord.conf file and kill -HUP or otherwise restart the
  105. supervisord process. This file has several example program
  106. definitions.
  107. Supervisord accepts a number of command-line overrides. Type
  108. 'supervisord -h' for an overview.
  109. Running Supervisorctl
  110. To start supervisorctl, run $BINDIR/supervisorctl. A shell will
  111. be presented that will allow you to control the processes that are
  112. currently managed by supervisord. Type "help" at the prompt to get
  113. information about the supported commands.
  114. supervisorctl may be invoked with "one time" commands when invoked
  115. with arguments from a command line. An example: "supervisorctl stop
  116. all". If arguments are present on the supervisorctl command-line,
  117. it will prevent the interactive shell from being invoked. Instead,
  118. the command will be executed and supervisorctl will exit.
  119. If supervisorctl is invoked in interactive mode against a
  120. supervisord that requires authentication, you will be asked for
  121. authentication credentials.
  122. Components
  123. Supervisord
  124. The server piece of the supervisor is named "supervisord". It is
  125. responsible for responding to commands from the client process as
  126. well as restarting crashed or exited processes. It is meant to be
  127. run as the root user in most production setups. NOTE: see
  128. "Security Notes" at the end of this document for caveats!
  129. The server process uses a configuration file. This is typically
  130. located in "/etc/supervisord.conf". This configuration file is an
  131. "Windows-INI" style config file. It is important to keep this
  132. file secure via proper filesystem permissions because it may
  133. contain unencrypted usernames and passwords.
  134. Supervisorctl
  135. The command-line client piece of the supervisor is named
  136. "supervisorctl". It provides a shell-like interface to the
  137. features provided by supervisord. From supervisorctl, a user can
  138. connect to different supervisord processes, get status on the
  139. subprocesses controlled by a supervisord, stop and start
  140. subprocesses of a supervisord, and get lists of running processes
  141. of a supervisord.
  142. The command-line client talks to the server across a UNIX domain
  143. socket or an Internet socket. The server can assert that the user
  144. of a client should present authentication credentials before it
  145. allows him to perform commands. The client process may use the
  146. same configuration file as the server; any configuration file with
  147. a [supervisorctl] section in it will work.
  148. Web Server
  149. A (sparse) web user interface with functionality comparable to
  150. supervisorctl may be accessed via a browser if you start
  151. supervisord against an internet socket. Visit the server URL
  152. (e.g. http://localhost:9001/) to view and control process status
  153. through the web interface after changing the configuration file's
  154. 'http_port' parameter appropriately.
  155. XML-RPC Interface
  156. The same HTTP server which serves the web UI serves up an XML-RPC
  157. interface that can be used to interrogate and control supervisor
  158. and the programs it runs. To use the XML-RPC interface, connect
  159. to supervisor's http port with any XML-RPC client library and run
  160. commands against it. An example of doing this using Python's
  161. xmlrpclib client library::
  162. import xmlrpclib
  163. server = xmlrpclib.Server('http://localhost:9001')
  164. Call methods against the supervisor and its subprocesses by using
  165. the 'supervisor' namespace::
  166. server.supervisor.getState()
  167. You can get a list of methods supported by supervisor's XML-RPC
  168. interface by using the XML-RPC 'system.listMethods' API:
  169. server.system.listMethods()
  170. You can see help on a method by using the 'system.methodHelp' API
  171. against the method::
  172. print server.system.methodHelp('supervisor.shutdown')
  173. Supervisor's XML-RPC interface also supports the nascent XML-RPC
  174. multicall API described at
  175. http://www.xmlrpc.com/discuss/msgReader$1208.
  176. You can extend supervisor functionality with new XML-RPC API
  177. methods by adding new top-level RPC interfaces as necessary. See
  178. "Configuration File ['rpcinterface:x] Section Settings" in this
  179. file.
  180. Configuration File '[supervisord]' Section Settings
  181. The supervisord.conf log file contains a section named
  182. '[supervisord]' in which global settings for the supervisord process
  183. should be inserted. These are:
  184. 'http_port' -- Either a TCP host:port value or (e.g. 127.0.0.1:9001)
  185. or a path to a UNIX domain socket (e.g. /tmp/supervisord.sock) on
  186. which supervisor will listen for HTTP/XML-RPC requests.
  187. Supervisorctl itself uses XML-RPC to communicate with supervisord
  188. over this port.
  189. 'sockchmod' -- Change the UNIX permission mode bits of the http_port
  190. UNIX domain socket to this value (ignored if using a TCP socket).
  191. Default: 0700.
  192. 'sockchown' -- Change the user and group of the socket file to this
  193. value. May be a username (e.g. chrism) or a username and group
  194. separated by a dot (e.g. chrism.wheel) Default: do not change.
  195. 'umask' -- The umask of the supervisord process. Default: 022.
  196. 'logfile' -- The path to the activity log of the supervisord process.
  197. 'logfile_maxbytes' -- The maximum number of bytes that may be
  198. consumed by the activity log file before it is rotated (suffix
  199. multipliers like "KB", "MB", and "GB" can be used in the value).
  200. Set this value to 0 to indicate an unlimited log size. Default:
  201. 50MB.
  202. 'logfile_backups' -- The number of backups to keep around resulting
  203. from activity log file rotation. Set this to 0 to indicate an
  204. unlimited number of backups. Default: 10.
  205. 'loglevel' -- The logging level, dictating what is written to the
  206. activity log. One of 'critical', 'error', 'warn', 'info', 'debug'
  207. or 'trace'. Note that at log level 'trace', the supervisord log
  208. file will record the stderr/stdout output of its child processes,
  209. which is useful for debugging. Default: info.
  210. 'pidfile' -- The location in which supervisord keeps its pid file.
  211. 'nodaemon' -- If true, supervisord will start in the foreground
  212. instead of daemonizing. Default: false.
  213. 'minfds' -- The minimum number of file descriptors that must be
  214. available before supervisord will start successfully. Default:
  215. 1024.
  216. 'minprocs' -- The minimum nymber of process descriptors that must be
  217. available before supervisord will start successfully. Default: 200.
  218. 'nocleanup' -- prevent supervisord from clearing any existing "AUTO"
  219. log files at startup time. Default: false.
  220. 'http_username' -- the username required for authentication to our
  221. HTTP server. Default: none.
  222. 'http_password' -- the password required for authentication to our
  223. HTTP server. Default: none.
  224. 'childlogdir' -- the directory used for AUTO log files. Default:
  225. value of Python's tempfile.get_tempdir().
  226. 'user' -- if supervisord is run as root, switch users to this UNIX
  227. user account before doing any meaningful processing. This value has
  228. no effect if supervisord is not run as root. Default: do not switch
  229. users.
  230. 'directory' -- When supervisord daemonizes, switch to this
  231. directory. Default: do not cd.
  232. 'strip_ansi' -- Strip all ANSI escape sequences from process log
  233. files.
  234. 'environment' -- A list of key/value pairs in the form
  235. "KEY=val,KEY2=val2" that will be placed in the supervisord process'
  236. environment (and as a result in all of its child process'
  237. environments). Default: none. **Note** that subprocesses will
  238. inherit the environment variables of the shell used to start
  239. "supervisord" except for the ones overridden here and within the
  240. program's "environment" configuration stanza. See "Subprocess
  241. Environment" below.
  242. 'identifier' -- The identifier for this supervisor server, used by
  243. the RPC interface. Default: 'supervisor'.
  244. Configuration File '[supervisorctl]' Section Settings
  245. The configuration file may contain settings for the supervisorctl
  246. interactive shell program. These options are listed below.
  247. 'serverurl' -- The URL that should be used to access the supervisord
  248. server, e.g. "http://localhost:9001". For UNIX domain sockets, use
  249. "unix:///absolute/path/to/file.sock".
  250. 'username' -- The username to pass to the supervisord server for use
  251. in authentication (should be same as 'http_username' in supervisord
  252. config). Optional.
  253. 'password' -- The password to pass to the supervisord server for use
  254. in authentication (should be the same as 'http_password' in
  255. supervisord config). Optional.
  256. 'prompt' -- String used as supervisorctl prompt. Default: supervisor.
  257. Configuration File '[program:x]' Section Settings
  258. The .INI file must contain one or more 'program' sections in order
  259. for supervisord to know which programs it should start and control.
  260. A sample program section has the following structure, the options of
  261. which are described below it::
  262. [program:foo]
  263. command=/path/to/foo
  264. process_name = %(program_name)s
  265. numprocs=1
  266. priority=1
  267. autostart=true
  268. autorestart=true
  269. startsecs=1
  270. startretries=3
  271. exitcodes=0,2
  272. stopsignal=TERM
  273. stopwaitsecs=10
  274. user=nobody
  275. redirect_stderr=false
  276. stdout_logfile=AUTO
  277. stdout_logfile_maxbytes=50MB
  278. stdout_logfile_backups=10
  279. stdout_capturefile=AUTO
  280. stderr_logfile=AUTO
  281. stderr_logfile_maxbytes=50MB
  282. stderr_logfile_backups=10
  283. stderr_capturefile=AUTO
  284. environment=A=1,B=2
  285. '[program:foo]' -- the section header, required for each program.
  286. 'programname' is a descriptive name (arbitrary) used to describe the
  287. program being run. It must not include a colon character or a
  288. bracket character.
  289. 'command' -- the command that will be run when this program is
  290. started. The command can be either absolute,
  291. e.g. ('/path/to/programname') or relative ('programname'). If it is
  292. relative, the PATH will be searched for the executable. Programs
  293. can accept arguments, e.g. ('/path/to/program foo bar'). The
  294. command line can used double quotes to group arguments with spaces
  295. in them to pass to the program, e.g. ('/path/to/program/name -p "foo
  296. bar"'). Note that the value of 'command' may include Python string
  297. expressions, e.g. "/path/to/programname --port=80%(process_num)02d"
  298. might expand to "/path/to/programname --port=8000" at runtime.
  299. String expressions are evaluated against a dictionary containing
  300. "group_name", "process_num" and "program_name". **Controlled
  301. programs should themselves not be daemons, as supervisord assumes it
  302. is responsible for daemonizing its subprocesses (see "Nondaemonizing
  303. of Subprocesses" later in this document).**
  304. 'process_name' -- a Python string expression that is used to compose
  305. the supervisor process name for this process. You usually don't
  306. need to worry about setting this unless you change 'numprocs'. The
  307. string expression is evaluated against a dictionary that includes
  308. "group_name", "process_num" and "program_name". Default:
  309. %(program_name)s.
  310. 'numprocs' -- Supervisor will start as many instances of this
  311. program as named by numprocs. Note that if numprocs > 1, the
  312. 'process_name' expression must include '%(process_num)s' (or any
  313. other valid Python string expression that includes 'process_num')
  314. within it. Default: 1.
  315. 'priority' -- the relative priority of the program in the start and
  316. shutdown ordering. Lower priorities indicate programs that start
  317. first and shut down last at startup and when aggregate commands are
  318. used in various clients (e.g. "start all"/"stop all"). Higher
  319. priorities indicate programs that start last and shut down first.
  320. Default: 999.
  321. 'autostart' -- If true, this program will start automatically when
  322. supervisord is started. Default: true.
  323. 'autorestart' -- If true, when the program exits (either expectedly
  324. or unexpectedly), supervisor will restart it automatically.
  325. Default: true.
  326. 'startsecs' -- The total number of seconds which the program needs
  327. to stay running after a startup to consider the start successful.
  328. If the program does not stay up for this many seconds after it is
  329. started, even if it exits with an "expected" exit code (see
  330. "exitcodes"), the startup will be considered a failure. Set to 0
  331. to indicate that the program needn't stay running for any particular
  332. amount of time. Default: 1
  333. 'startretries' -- The number of serial failure attempts that
  334. supervisord will allow when attempting to start the program before
  335. giving up and puting the process into an ERROR state. Default: 3.
  336. 'exitcodes' -- The list of 'expected' exit codes for this program.
  337. Supervisor log messages will note if the program exits with an exit
  338. code which is not in this list and a stop of the program has not
  339. been explicitly requested. Default: 0,2.
  340. 'stopsignal' -- The signal used to kill the program when a stop is
  341. requested. This can be any of TERM, HUP, INT, QUIT, KILL, USR1, or
  342. USR2. Default: TERM.
  343. 'stopwaitsecs' -- The number of seconds to wait for the program to
  344. return a SIGCHILD to supervisord after the program has been sent a
  345. stopsignal. If this number of seconds elapses before supervisord
  346. receives a SIGCHILD from the process, supervisord will attempt to
  347. kill it with a final SIGKILL. Default: 10.
  348. 'user' -- If supervisord is running as root, this UNIX user account
  349. will be used as the account which runs the program. If supervisord
  350. is not running as root, this option has no effect. Defaut: do not
  351. switch users.
  352. 'redirect_stderr' -- If true, cause the process' stderr output to be
  353. sent back to supervisor on it's stdout file descriptor (in UNIX
  354. shell terms, this is the equivalent of executing "/the/program
  355. 2>&1". Default: false.
  356. 'stdout_logfile' -- Put process stdout output in this file (and if
  357. redirect_stderr is true, also place stderr output in this file). If
  358. 'stdout_logfile' is unset or set to 'AUTO', supervisor will
  359. automatically choose a file location. If this is set to 'NONE',
  360. supervisord will create no log file. AUTO log files and their
  361. backups will be deleted when supervisord restarts. Default: AUTO.
  362. 'stdout_logfile_maxbytes' -- The maximum number of bytes that may be
  363. consumed by stdout_logfile before it is rotated (suffix multipliers
  364. like "KB", "MB", and "GB" can be used in the value). Set this value
  365. to 0 to indicate an unlimited log size. Default: 50MB.
  366. 'stdout_logfile_backups' -- The number of stdout_logfile backups to
  367. keep around resulting from process stdout log file rotation. Set
  368. this to 0 to indicate an unlimited number of backups. Default: 10.
  369. 'stdout_capturefile' -- file written to when process is in "stdout
  370. capture mode" (see "Capture Mode and Process Communication Events"
  371. later in this document). May be a file path, NONE, or AUTO.
  372. Default: AUTO.
  373. 'stderr_logfile' -- Put process stderr output in this file unless
  374. redirect_stderr is true. Accepts the same value types as
  375. "stdout_logfile". Default: AUTO.
  376. 'stderr_logfile_maxbytes' -- The maximum number of bytes before
  377. logfile rotation for stderr_logfile. Accepts the same value types
  378. as "stdout_logfile_maxbytes". Default: 50MB.
  379. 'stderr_logfile_backups' -- The number of backups to keep around
  380. resulting from process stderr log file rotation. Default: 10.
  381. 'stderr_capturefile' -- file written to when process is in "stderr
  382. capture mode" (see "Capture Mode and Process Communication Events"
  383. later in this document). May be a file path, NONE, or AUTO.
  384. Default: AUTO.
  385. 'environment' -- A list of key/value pairs in the form
  386. "KEY=val,KEY2=val2" that will be placed in the child process'
  387. environment. Default: none. **Note** that the subprocess will
  388. inherit the environment variables of the shell used to start
  389. "supervisord" except for the ones overridden here. See "Subprocess
  390. Environment" below.
  391. Configuration File '[group:x]' Section Settings
  392. XXX TODO
  393. Configuration File '[eventlistener:x]' Section Settings
  394. XXX TODO
  395. Configuration File '[rpcinterface:x]' Section Settings (ADVANCED)
  396. Changing "rpcinterface:x" settings in the configuration file is only
  397. useful for people who wish to extend supervisor with additional
  398. behavior.
  399. In the sample config file, there is a section which is named
  400. "rpcinterface:supervisor". By default it looks like this:
  401. [rpcinterface:supervisor]
  402. supervisor.rpcinterface_factory = supervisor.xmlrpc:make_main_rpcinterface
  403. This section must remain in the configuration for the standard setup
  404. of supervisor to work properly. If you don't want supervisor to do
  405. anything it doesn't already do out of the box, this is all you need
  406. to know about this type of section.
  407. However, if you wish to add rpc interface namespaces to a custom
  408. version of supervisor, you may add additional [rpcinterface:foo]
  409. sections, where "foo" represents the namespace of the interface
  410. (from the web root), and the value named by
  411. "supervisor.rpcinterface_factory" is a factory callable which should
  412. have a function signature that accepts a single positional argument
  413. "supervisord" and as many keyword arguments as required to perform
  414. configuration. Any key/value pairs defined within the
  415. rpcinterface:foo section will be passed as keyword arguments to the
  416. factory. Here's an example of a factory function, created in the
  417. package "my.package"::
  418. def make_another_rpcinterface(supervisord, **config):
  419. retries = int(config.get('retries', 0))
  420. another_rpc_interface = AnotherRPCInterface(supervisord, retries)
  421. return another_rpc_interface
  422. And a section in the config file meant to configure
  423. it::
  424. [rpcinterface:another]
  425. supervisor.rpcinterface_factory = my.package:make_another_rpcinterface
  426. retries = 1
  427. Nondaemonizing of Subprocesses
  428. Programs run under supervisor *should not* daemonize themselves.
  429. Instead, they should run in the foreground and not detach from the
  430. "terminal" that starts them. The easiest way to tell if a command
  431. will run in the foreground is to run the command from a shell
  432. prompt. If it gives you control of the terminal back, it's
  433. daemonizing itself and that will be the wrong way to run it under
  434. supervisor. You want to run a command that essentially requires you
  435. to press Ctrl-C to get control of the terminal back. If it gives
  436. you a shell prompt back after running it without needing to press
  437. Ctrl-C, it's not useful under supervisor. All programs have options
  438. to be run in the foreground but there's no standard way to do it;
  439. you'll need to read the documentation for each program you want to
  440. do this with.
  441. Subprocess Environment
  442. Subprocesses will inherit the environment of the shell used to start
  443. the supervisord program. Several environment variables will be set
  444. by supervisor itself in the child's environment also, including
  445. "SUPERVISOR_ENABLED" (a flag indicating the process is under
  446. supervisor control), "SUPERVISOR_PROCESS_NAME" (the
  447. config-file-specified process name for this process) and
  448. "SUPERVISOR_GROUP_NAME" (the config-file-specified process group name
  449. for the child process).
  450. These environment variables may be overridden within the
  451. "environment" global config option (applies to all subprocesses) or
  452. within the per-program "environment" config option (applies only to
  453. the subprocess specified within the "program" section). These
  454. "environment" settings are additive. In other words, each
  455. subprocess' environment will consist of::
  456. The environment variables set within the shell used to start
  457. supervisord...
  458. ... added-to/overridden-by ...
  459. ... the environment variables set within the "environment" global
  460. config option ...
  461. ... added-to/overridden-by ...
  462. ... supervisor-specific environment variables
  463. ("SUPERVISOR_ENABLED", "SUPERVISOR_PROCESS_NAME",
  464. "SUPERVISOR_GROUP_NAME") ..
  465. ... added-to/overridden-by ...
  466. .. the environment variables set within the per-process
  467. "environment" config option.
  468. No shell is executed by supervisord when it runs a subprocess, so
  469. settings such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not
  470. changed from their defaults or otherwise reassigned. This is
  471. particularly important to note when you are running a program from a
  472. supervisord run as root with a "user=" stanza in the configuration.
  473. Unlike cron, supervisord does not attempt to divine and override
  474. "fundamental" environment variables like USER, PATH, HOME, and
  475. LOGNAME when it performs a setuid to the user defined within the
  476. "user=" program config option. If you need to set environment
  477. variables for a particular program that might otherwise be set by a
  478. shell invocation for a particular user, you must do it explicitly
  479. within the "environment=" program config option. For example::
  480. [program:apache]
  481. command=/home/chrism/bin/httpd -DNO_DETACH
  482. user=chrism
  483. environment=HOME=/home/chrism,USER=chrism
  484. Examples of Program Configurations
  485. Apache 2.0.54::
  486. [program:apache]
  487. command=/usr/sbin/httpd -DNO_DETACH
  488. Postgres 8.14::
  489. [program:postgres]
  490. command=/path/to/postmaster
  491. ; we use the "fast" shutdown signal SIGINT
  492. stopsignal=INT
  493. redirect_stderr=true
  494. Zope 2.8 instances and ZEO::
  495. [program:zeo]
  496. command=/path/to/runzeo
  497. priority=1
  498. [program:zope1]
  499. command=/path/to/instance/home/bin/runzope
  500. priority=2
  501. redirect_stderr=true
  502. [program:zope2]
  503. command=/path/to/another/instance/home/bin/runzope
  504. priority=2
  505. redirect_stderr=true
  506. OpenLDAP slapd::
  507. [program:slapd]
  508. command=/path/to/slapd -f /path/to/slapd.conf -h ldap://0.0.0.0:8888
  509. Process States
  510. A process controlled by supervisord will be in one of the below
  511. states at any given time. You may see these state names in various
  512. user interface elements.
  513. STOPPED (0) -- The process has been stopped due to a stop request or
  514. has never been started.
  515. STARTING (10) -- The process is starting due to a start request.
  516. RUNNING (20) -- The process is running.
  517. BACKOFF (30) -- The process entered the STARTING state but
  518. subsequently exited too quickly to move to the
  519. RUNNING state.
  520. STOPPING (40) -- The process is stopping due to a stop request.
  521. EXITED (100) -- The process exited from the RUNNING state (expectedly
  522. or unexpectedly).
  523. FATAL (200) -- The process could not be started successfully.
  524. UNKNOWN (1000) -- The process is in an unknown state (programming error).
  525. Process progress through these states as per the following directed
  526. graph::
  527. --> STOPPED
  528. / |
  529. | |
  530. | |
  531. STOPPING |
  532. ^ ^ V
  533. | \--- STARTING <-----> BACKOFF
  534. | / ^ |
  535. | V | |
  536. \-- RUNNING / \ |
  537. | / \ V
  538. V / \ ----- FATAL
  539. EXITED
  540. A process is in the STOPPED state if it has been stopped
  541. adminstratively or if it has never been started.
  542. When an autorestarting process is in the BACKOFF state, it will be
  543. automatically restarted by supervisord. It will switch between
  544. STARTING and BACKOFF states until it becomes evident that it cannot
  545. be started because the number of startretries has exceeded the
  546. maximum, at which point it will transition to the FATAL state. Each
  547. start retry will take progressively more time.
  548. An autorestarted process will never be automtatically restarted if
  549. it ends up in the FATAL state (it must be manually restarted from
  550. this state).
  551. A process transitions into the STOPPING state via an administrative
  552. stop request, and will then end up in the STOPPED state.
  553. A process that cannot be stopped successfully will stay in the
  554. STOPPING state forever. This situation should never be reached
  555. during normal operations as it implies that the process did not
  556. respond to a final SIGKILL, which is "impossible" under UNIX.
  557. State transitions which always require user action to invoke are
  558. these:
  559. FATAL -> STARTING
  560. RUNNING -> STOPPING
  561. State transitions which typically, but not always, require user
  562. action to invoke are these, with exceptions noted:
  563. STOPPED -> STARTING (except at supervisord startup if process is
  564. configured to autostart)
  565. EXITED -> STARTING (except if process is configured to autorestart)
  566. All other state transitions are managed by supervisord
  567. automatically.
  568. Supervisor Events
  569. At certain predefined points during supervisord's operation, "event
  570. notifications" are emitted. An event denotes that something
  571. potentially interesting happened. Event listeners (see the "Event
  572. Listeners" section below) can be configured to subscribe to event
  573. notifications selectively, and may perform arbitrary actions based
  574. on an event notification (send email, make an HTTP request, etc).
  575. Event types that may be subscribed to by event listeners are
  576. predefined by supervisor and fall into several major categories,
  577. including "process state change", "process communication",
  578. "supervisor state change", and "event system meta" events. These
  579. are described in detail below.
  580. EVENT -- The base event type. This event type is abstract. It will
  581. never be sent directly. Subscribing to this event type will cause a
  582. subscriber to receive all event notifications emitted by supervisor.
  583. Subtypes of EVENT:
  584. PROCESS_STATE_CHANGE -- The value of this event type will be the
  585. process name. Subscribing to this event type will cause a
  586. subscriber to receive event notifications of all the types listed
  587. below in "Subtypes of PROCESS_STATE_CHANGE".
  588. The serialized body of a PROCESS_STATE_CHANGE event (and all
  589. subtypes) is in the form::
  590. process_name: <name>
  591. group_name: <name>
  592. Subtypes of PROCESS_STATE_CHANGE:
  593. STARTING -- indicates a process has moved from a state to the
  594. STARTING state. Subscribing to this event type will cause a
  595. subscriber to receive event notifications of all the types
  596. listed below in "Subtypes of STARTING".
  597. Subtypes of STARTING:
  598. STARTING_FROM_STOPPED -- subtype of STARTING, indicates a
  599. process has moved from the STOPPED state from the STARTING
  600. state.
  601. STARTING_FROM_BACKOFF -- subtype of STARTING, indicates a
  602. process has moved from BACKOFF state to the STARTING state.
  603. STARTING_FROM_EXITED -- subtype of STARTING, indicates a
  604. process has moved from the EXITED state to the STARTING
  605. state.
  606. STARTING_FROM_FATAL -- subtype of STARTING, indicates a
  607. process has moved to the FATAL state to the STARTING state.
  608. RUNNING -- inidicates a process has moved from the STARTING state
  609. to the RUNNING state.
  610. BACKOFF -- indicates a process has moved from the STARTING state
  611. to the BACKOFF state.
  612. STOPPING_FROM_RUNNING -- indicates a process has moved from the
  613. RUNNING state to the STOPPING state.
  614. STOPPING_FROM_STARTING -- indicates a process has moved from
  615. the RUNNING state to the STARTING state.
  616. EXITED_OR_STOPPED -- indicates a process has undergone a state
  617. change which caused it to move to the EXITED or STOPPED state.
  618. Subtypes of EXITED_OR_STOPPED:
  619. EXITED -- indicates a process has moved from the RUNNING
  620. state to the EXITED state.
  621. STOPPED -- indicates a process has moved from the STOPPING
  622. state to the STOPPED state.
  623. FATAL -- indicates a process has moved from the BACKOFF state
  624. to the FATAL state.
  625. UNKNOWN -- indicates a process has moved from a state to the
  626. UNKNOWN state (indicates an error in supervisord).
  627. PROCESS_COMMUNICATION -- an event type raised when any process
  628. attempts to send information between <!--XSUPERVISOR:BEGIN--> and
  629. <!--XSUPERVISOR:END--> tags in its output. Subscribing to this
  630. event type will cause a subscriber to receive event notifications
  631. of all the types listed below in "Subtypes of
  632. PROCESS_COMMUNICATION".
  633. The serialized body of a PROCESS_COMMUNICATION event (and all
  634. subtypes) is::
  635. process_name: <name>
  636. group_name: <name>
  637. <data>
  638. Subtypes of PROCESS_COMMUNICATION:
  639. PROCESS_COMMUNICATION_STDOUT -- indicates a process has sent a
  640. message to supervisor on its stdout file descriptor.
  641. PROCESS_COMMUNICATION_STDERR -- indicates a process has sent a
  642. message to supervisor on its stderr file descriptor.
  643. SUPERVISOR_STATE_CHANGE -- an event type raised when supervisor's
  644. state changes. There is no value. Subscribing to this event type
  645. will cause a subscriber to receive event notifications of all the
  646. types listed below in "Subtypes of SUPERVISOR_STATE_CHANGE".
  647. The serialization of a SUPERVISOR_STATE_CHANGE event is the empty
  648. string.
  649. Subtypes of SUPERVISOR_STATE_CHANGE:
  650. SUPERVISOR_RUNNING -- indicates that supervisor has started.
  651. SUPERVISOR_STOPPING -- indicates that supervisor is stopping or
  652. restarting.
  653. EVENT_BUFFER_OVERFLOW -- an event type raised when a listener
  654. pool's event buffer is overflowed (as can happen when an event
  655. listener pool cannot keep up with all of the events sent to it).
  656. When the pool's event buffer is overflowed, the oldest event in
  657. the buffer is thrown out.
  658. The serialization of an EVENT_BUFFER_OVERFLOW body
  659. is::
  660. group_name: <name>
  661. event_type: <type of discarded event>
  662. Event Listeners
  663. XXX TODO
  664. Capture Mode and Process Communication Events
  665. XXX TODO
  666. Signals
  667. Killing supervisord with SIGHUP will stop all processes, reload the
  668. configuration from the config file, and restart all processes.
  669. Killing supervisord with SIGUSR2 will close and reopen the
  670. supervisord activity log and child log files.
  671. Access Control
  672. The UNIX permissions on the socket effectively control who may send
  673. commands to the server. HTTP basic authentication provides access
  674. control for internet and UNIX domain sockets as necessary.
  675. Security Notes
  676. I have done my best to assure that use of a supervisord process
  677. running as root cannot lead to unintended privilege escalation, but
  678. caveat emptor. Particularly, it is not as paranoid as something
  679. like DJ Bernstein's "daemontools", inasmuch as "supervisord" allows
  680. for arbitrary path specifications in its configuration file to which
  681. data may be written. Allowing arbitrary path selections can create
  682. vulnerabilities from symlink attacks. Be careful when specifying
  683. paths in your configuration. Ensure that supervisord's
  684. configuration file cannot be read from or written to by unprivileged
  685. users and that all files installed by the supervisor package have
  686. "sane" file permission protection settings. Additionally, ensure
  687. that your PYTHONPATH is sane and that all Python standard library
  688. files have adequate file permission protections. Then, pray to the
  689. deity of your choice.
  690. Other Notes
  691. Some examples of shell scripts to start services under supervisor
  692. can be found "here":http://www.thedjbway.org/services.html. These
  693. examples are actually for daemontools but the premise is the same
  694. for supervisor. Another collection of recipes for starting various
  695. programs in the foreground is
  696. "here":http://smarden.org/runit/runscripts.html .
  697. Some processes (like mysqld) ignore signals sent to the actual
  698. process/thread which is created by supervisord. Instead, a
  699. "special" thread/process is created by these kinds of programs which
  700. is responsible for handling signals. This is problematic, because
  701. supervisord can only kill a pid which it creates itself, not any
  702. child thread or process of the program it creates. Fortunately,
  703. these programs typically write a pidfile which is meant to be read
  704. in order to kill the process. As a workaround for this case, a
  705. special "pidproxy" program can handle startup of these kinds of
  706. processes. The pidproxy program is a small shim that starts a
  707. process, and upon the receipt of a signal, sends the signal to the
  708. pid provided in a pidfile. A sample supervisord configuration
  709. program entry for a pidproxy-enabled program is provided here::
  710. [program:mysql]
  711. command=/path/to/pidproxy /path/to/pidfile /path/to/mysqld_safe
  712. The pidproxy program is named 'pidproxy.py' and is in the
  713. supervisor distribution.
  714. FAQ
  715. My program never starts and supervisor doesn't indicate any error:
  716. Make sure the "x" bit is set on the executable file you're using in
  717. the command= line.
  718. How can I tell if my program is running under supervisor? Supervisor
  719. and its subprocesses share an environment variable
  720. "SUPERVISOR_ENABLED". When a process is run under supervisor, your
  721. program can check for the presence of this variable to determine
  722. whether it is running under supervisor (new in 2.0).
  723. My command line works fine when I invoke it by hand from a shell
  724. prompt, but when I use the same command line in a supervisor
  725. "command=" section, the program fails mysteriously. Why? This may
  726. be due to your process' dependence on environment variable settings.
  727. See "Subprocess Environment" in this document.
  728. Reporting Bugs
  729. Please report bugs at http://www.plope.com/software/collector .
  730. Author Information
  731. Chris McDonough (chrism@plope.com)
  732. http://www.plope.com