dinit-service.5.m4 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. changequote(`@@@',`$$$')dnl
  2. @@@.TH DINIT-SERVICE "5" "$$$MONTH YEAR@@@" "Dinit $$$VERSION@@@" "Dinit \- service management system"
  3. .SH NAME
  4. Dinit service description files
  5. .\"
  6. .SH SYNOPSIS
  7. .\"
  8. .ft CR
  9. /etc/dinit.d/\fIservice-name\fR, $HOME/dinit.d/\fIservice-name\fR
  10. .ft
  11. .\"
  12. .SH DESCRIPTION
  13. .\"
  14. The service description files for \fBDinit\fR each describe a service. The name
  15. of the file corresponds to the name of the service it describes.
  16. .LP
  17. Service description files specify the various attributes of a service. A
  18. service description file is named after the service it represents, and is
  19. a plain-text file with simple key-value format. The description files are
  20. located in a service description directory; by default, the system process
  21. searches \fI/etc/dinit.d\fR, \fI/usr/local/lib/dinit.d\fR and
  22. \fI/lib/dinit.d\fR, while a user process searches \fI$HOME/dinit.d\fR.
  23. .LP
  24. All services have a \fItype\fR and a set of \fIdependencies\fR. Service
  25. types are discussed in the following subsection. If a service depends on
  26. another service, then starting the first service causes the second to start
  27. also; depending on the type of dependency, if the second service fails to
  28. start, the dependent may have its startup aborted. For a service which will
  29. represent a running process, the process is not generally launched until the
  30. dependencies are all satisfied. If a service has a hard dependency on another
  31. which becomes stopped, the dependent service must also stop. A service
  32. process will not be signaled to terminate until the service's dependents have stopped.
  33. .\"
  34. .SS SERVICE TYPES
  35. .\"
  36. There are four basic types of service:
  37. .IP \(bu
  38. \fBProcess\fR services. This kind of service runs as a single process; starting
  39. the service simply requires starting the process; stopping the service is
  40. accomplished by stopping the process (via sending it a signal).
  41. .IP \(bu
  42. \fBBgprocess\fR services ("background process" services). This kind of
  43. service is similar to a regular process service, but the process daemonizes
  44. or otherwise forks from the original process which starts it, and the
  45. process ID is written to a file. Dinit can read the process ID from the
  46. file and, if it is running as the system init process, can supervise it.
  47. .IP \(bu
  48. \fBScripted\fR services are services which are started and stopped by a
  49. command (which need not actually be a script, despite the name). They can
  50. not be supervised.
  51. .IP \(bu
  52. \fBInternal\fR services do not run as an external process at all. They can
  53. be started and stopped without any external action. They are useful for
  54. grouping other services (via service dependencies).
  55. .\"
  56. .SS SERVICE PROPERTIES
  57. .\"
  58. This section described the various service properties that can be specified
  59. in a service description file. Each line of the file can specify a single
  60. property value, expressed as "\fIproperty-name\fR = \fIvalue\fR". Comments
  61. begin with a hash mark (#) and extend to the end of the line (they must be
  62. separated from setting values by at least one whitespace character). Values
  63. are interpreted literally, except that:
  64. .\"
  65. .IP \(bu
  66. White space (comprised of spaces, tabs, etc) is collapsed to a single space.
  67. .IP \(bu
  68. Double quotes (") can be used around all or part of a property value, to
  69. prevent whitespace collapse and prevent interpretation of other special
  70. characters (such as "#") inside the quotes. The quote characters are not
  71. considered part of the parameter value.
  72. .IP \(bu
  73. A backslash (\\) can be used to escape the next character, causing it to
  74. lose any special meaning and become part of the property value. A double
  75. backslash (\\\\) is collapsed to a single backslash within the parameter
  76. value.
  77. .LP
  78. The following properties can be specified:
  79. .TP
  80. \fBtype\fR = {process | bgprocess | scripted | internal}
  81. Specifies the service type.
  82. .TP
  83. \fBcommand\fR = \fIcommand-string\fR
  84. Specifies the command, including command-line arguments, for starting the
  85. process. Applies only to \fBprocess\fR, \fBbgprocess\fR and \fBscripted\fR
  86. services.
  87. .TP
  88. \fBstop\-command\fR = \fIcommand-string\fR
  89. Specifies the command to stop the service. Applicable only to \fBscripted\fR
  90. services.
  91. .TP
  92. \fBworking-dir\fR = \fIdirectory\fR
  93. Specifies the working directory for this service. For a scripted service, this
  94. affects both the start command and the stop command.
  95. .TP
  96. \fBrun\-as\fR = \fIuser-id\fR
  97. Specifies which user to run the process(es) for this service as. Specify as a
  98. username or numeric ID. If specified by name, the group for the process will
  99. also be set to the primary group of the specified user.
  100. .TP
  101. \fBrestart\fR = {yes | true | no | false}
  102. Indicates whether the service should automatically restart if it stops for
  103. any reason (including unexpected process termination, service dependency
  104. stopping, or user-initiated service stop).
  105. .TP
  106. \fBsmooth\-recovery\fR = {yes | true | no | false}
  107. Applies only to \fBprocess\fR and \fBbgprocess\fR services. When set true/yes,
  108. an automatic process restart can be performed without first stopping any
  109. dependent services. This setting is meaningless if the \fBrestart\fR setting
  110. is set to false.
  111. .TP
  112. \fBrestart\-delay\fR = \fIXXX.YYYY\fR
  113. Specifies the minimum time between automatic restarts. Enforcing a sensible
  114. minimum prevents Dinit from consuming a large number of process cycles in
  115. case a process continuously fails immediately after it is started. The
  116. default is 0.2 (200 milliseconds).
  117. .TP
  118. \fBrestart\-limit\-interval\fR = \fIXXX.YYYY\fR
  119. Sets the interval, in seconds, over which restarts are limited. If a process
  120. automatically restarts more than a certain number of times (specified by the
  121. \fBrestart-limit-count\fR setting) in this time interval, it will not restart
  122. again. The default value is 10 seconds.
  123. .TP
  124. \fBrestart\-limit\-count\fR = \fINNN\fR
  125. Specifies the maximum number of times that a service can automatically restart
  126. over the interval specified by \fBrestart\-limit\-interval\fR. Specify a value
  127. of 0 to disable the restart limit.
  128. .TP
  129. \fBstart\-timeout\fR = \fIXXX.YYY\fR
  130. Specifies the time in seconds allowed for the service to start. If the
  131. service takes longer than this, its process group is sent a SIGINT signal
  132. and enters the "stopping" state (this may be subject to a stop timeout, as
  133. specified via \fBstop\-timeout\fR, after which the process group will be
  134. terminated via SIGKILL). The timeout period begins only when all dependencies
  135. have been stopped. The default timeout is 60 seconds. Specify a value of 0 to
  136. allow unlimited start time.
  137. .TP
  138. \fBstop\-timeout\fR = \fIXXX.YYY\fR
  139. Specifies the time in seconds allowed for the service to stop. If the
  140. service takes longer than this, its process group is sent a SIGKILL signal
  141. which should cause it to terminate immediately. The timeout period begins
  142. only when all dependent services have already stopped. The default
  143. timeout is 10 seconds. Specify a value of 0 to allow unlimited stop time.
  144. .TP
  145. \fBpid\-file\fR = \fIpath-to-file\fR
  146. For \fBbgprocess\fR type services only; specifies the path of the file where
  147. daemon will write its process ID before detaching. Dinit will read the
  148. contents of this file when starting the service, once the initial process
  149. exits, will supervise the process with the discovered process ID, and may
  150. send signals to the process ID to stop the service; if Dinit runs as a
  151. privileged user the path should therefore not be writable by unprivileged
  152. users.
  153. .TP
  154. \fBdepends\-on\fR = \fIservice-name\fR
  155. This service depends on the named service. Starting this service will start
  156. the named service; the command to start this service will not be executed
  157. until the named service has started. If the named service is stopped then
  158. this service will also be stopped.
  159. .TP
  160. \fBdepends\-ms\fR = \fIservice-name\fR
  161. This service has a "milestone" dependency on the named service. Starting this
  162. service will start the named service; this service will not start until the
  163. named service has started, and will fail to start if the named service does
  164. not start. Once the named service reaches the started state, however, the
  165. dependency is effectively dropped until this service is next started.
  166. .TP
  167. \fBwaits\-for\fR = \fIservice-name\fR
  168. When this service is started, wait for the named service to finish starting
  169. (or to fail starting) before commencing the start procedure for this service.
  170. Starting this service will automatically start the named service. If the
  171. named service fails to start, this service will start as usual (subject to
  172. other dependencies being met).
  173. .TP
  174. \fBwaits\-for.d\fR = \fIdirectory-path\fR
  175. For each file name in \fIdirectory-path\fR which does not begin with a dot,
  176. add a \fBwaits-for\fR dependency to the service with the same name. Note that
  177. contents of files in the specified directory are not significant; expected
  178. usage is to have symbolic links to the associated service description files,
  179. but this is not required. Failure to read the directory contents, or to find
  180. any of the services named within, is not considered fatal.
  181. The directory path, if not absolute, is relative to the directory containing
  182. the service description file.
  183. .TP
  184. \fBchain-to\fR = \fIservice-name\fR
  185. When this service terminates (i.e. starts successfully, and then stops of its
  186. own accord), the named service should be started. Note that the named service
  187. is not loaded until that time; naming an invalid service will not cause this
  188. service to fail to load.
  189. This can be used for a service that supplies an interactive "recovery mode"
  190. for another service; once the user exits the recovery shell, the primary
  191. service (as named via this setting) will then start. It also supports
  192. multi-stage system startup where later service description files reside on
  193. a separate filesystem that is mounted during the first stage; such service
  194. descriptions will not be found at initial start, and so cannot be started
  195. directly, but can be chained via this directive.
  196. The chain is not executed if the initial service was explicitly stopped, stopped
  197. due to a dependency stopping (for any reason), if it will restart (including due
  198. to a dependent restarting), or if its process terminates abnormally or with an
  199. exit status indicating an error.
  200. .TP
  201. \fBsocket\-listen\fR = \fIsocket-path\fR
  202. Pre-open a socket for the service and pass it to the service using the
  203. \fBsystemd\fR activation protocol. This by itself does not give so called
  204. "socket activation", but does allow that any process trying to connect to the
  205. specified socket will be able to do so, even before the service is properly
  206. prepared to accept connections.
  207. .TP
  208. \fBsocket\-permissions\fR = \fIoctal-permissions-mask\fR
  209. Gives the permissions for the socket specified using \fBsocket-listen\fR.
  210. Normally this will be 600 (user access only), 660 (user and group
  211. access), or 666 (all users). The default is 666.
  212. .TP
  213. \fBsocket\-uid\fR = {\fInumeric-user-id\fR | \fIusername\fR}
  214. Specifies the user (name or numeric ID) that should own the activation socket. If
  215. \fBsocket\-uid\fR is specified as a name without also specifying \fBsocket-gid\fR, then
  216. the socket group is the primary group of the specified user (as found in the
  217. system user database, normally \fI/etc/passwd\fR). If the \fBsocket\-uid\fR setting is
  218. not provided, the socket will be owned by the user id of the \fBdinit\fR process.
  219. .TP
  220. \fBsocket\-gid\fR = {\fInumeric-group-id\fR | \fIgroup-name\fR}
  221. Specifies the group of the activation socket. See discussion of
  222. \fBsocket\-uid\fR.
  223. .TP
  224. \fBterm\-signal\fR = {HUP | INT | QUIT | USR1 | USR2 | KILL}
  225. Specifies an additional signal to send to the process when requesting it
  226. to terminate (applies to 'process' services only). SIGTERM is always
  227. sent along with the specified signal, unless the \fBno\-sigterm\fR option is
  228. specified via the \fBoptions\fR parameter.
  229. .TP
  230. \fBready\-notification\fR = {\fBpipefd:\fR\fIfd-number\fR | \fBpipevar:\fR\fIenv-var-name\fR}
  231. Specifies the mechanism, if any, by which a process service will notify that it is ready
  232. (successfully started). If not specified, a process service is considered started as soon as it
  233. has begun execution. The two options are:
  234. .RS
  235. .IP \(bu
  236. \fBpipefd:\fR\fIfd-number\fR \(em the service will write a message to the specified file descriptor,
  237. which \fBdinit\fR sets up as the write end of a pipe before execution. This mechanism is compatible
  238. with the S6 supervision suite.
  239. .IP \(bu
  240. \fBpipevar:\fR\fIenv-var-name\fR \(em the service will write a message to file descriptor identified
  241. using the contents of the specified environment variable, which will be set by \fBdinit\fR before
  242. execution to a file descriptor (chosen arbitrarily) attached to the write end of a pipe.
  243. .RE
  244. .TP
  245. \fBlogfile\fR = \fIlog-file-path\fR
  246. Specifies the log file for the service. Output from the service process
  247. will go this file.
  248. .TP
  249. \fBoptions\fR = \fIoption\fR...
  250. Specifies various options for this service. See the \fBOPTIONS\fR section. This
  251. directive can be specified multiple times to set additional options.
  252. .TP
  253. \fBload-options\fR = \fIload_option\fR...
  254. Specifies options for interpreting other settings when loading this service
  255. description. Currently there is only one available option, \fBsub-vars\fR,
  256. which specifies that command line arguments in the form of \fB$NAME\fR should
  257. be replaced with the contents of the environment variable with the specified
  258. name. Note that no word-splitting is performed and the variable value always
  259. becomes a single argument; if the variable is not defined, it is replaced with
  260. an empty (zero-length) argument.
  261. .TP
  262. \fBinittab-id\fR = \fIid-string\fR
  263. When this service is started, if this setting (or the \fBinittab-line\fR setting) has a
  264. specified value, an entry will be created in the system "utmp" database which tracks
  265. processes and logged-in users. Typically this database is used by the "who" command to
  266. list logged-in users. The entry will be cleared when the service terminates.
  267. The \fBinittab-id\fR setting specifies the "inittab id" to be written in the entry for
  268. the process. The value is normally quite meaningless. However, it should be distinct
  269. (or unset) for separate processes. It is typically limited to a very short length.
  270. The "utmp" database is mostly a historical artifact. Access to it on some systems is
  271. prone to denial-of-service by unprivileged users. It is therefore recommended that this
  272. setting not be used. However, "who" and similar utilities may not work correctly without
  273. this setting (or \fBinittab-line\fR) enabled appropriately.
  274. This setting has no effect if Dinit was not built with support for writing to the "utmp"
  275. database.
  276. .TP
  277. \fBinittab-line\fR = \fItty-name-string\fR
  278. This specifies the tty line that will be written to the "utmp" database when this service
  279. is started. Normally, for a terminal login service, it would match the terminal device name
  280. on which the login process runs, without the "/dev/" prefix.
  281. See the description of the \fBinittab-id\fR setting for details.
  282. .TP
  283. \fBrlimit-nofile\fR = \fIresource-limits\fR
  284. Specifies the number of file descriptors that a process may have open simultaneously. See the
  285. \fBRESOURCE LIMITS\fR section.
  286. .TP
  287. \fBrlimit-core\fR = \fIresource-limits\fR
  288. Specifies the maximum size of the core dump file that will be generated for the process if it
  289. crashes (in a way that would result in a core dump). See the \fBRESOURCE LIMITS\fR section.
  290. .TP
  291. \fBrlimit-data\fR = \fIresource-limits\fR
  292. Specifies the maximum size of the data segment for the process, including statically allocated
  293. data and heap allocations. Precise meaning may vary between operating systems. See the
  294. \fBRESOURCE LIMITS\fR section.
  295. .TP
  296. \fBrlimit-addrspace\fR = \fIresource-limits\fR
  297. Specifies the maximum size of the address space of the process. See the \fBRESOURCE LIMITS\fR
  298. section. Note that some operating systems (notably OpenBSD) do not support this limit; the
  299. setting will be ignored on such systems.
  300. .\"
  301. .SS OPTIONS
  302. .\"
  303. These options are specified via the \fBoptions\fR parameter.
  304. .\"
  305. .TP
  306. \fBno\-sigterm\fR
  307. Specifies that the TERM signal should not be send to the process to terminate
  308. it. (Another signal can be specified using the \fBtermsignal\fR setting; if no
  309. other signal is specified, no signal will be sent, which usually means that
  310. the service will not terminate).
  311. .TP
  312. \fBruns\-on\-console\fR
  313. Specifies that this service uses the console; its input and output should be
  314. directed to the console (or precisely, to the device to which Dinit's standard
  315. output stream is connected). A service running on the console prevents other
  316. services from running on the console (they will queue for the console).
  317. The \fIinterrupt\fR key (normally control-C) will be active for process / scripted
  318. services that run on the console. Handling of an interrupt is determined by
  319. the service process, but typically will cause it to terminate.
  320. .TP
  321. \fBstarts\-on\-console\fR
  322. Specifies that this service uses the console during service startup. This is
  323. implied by \fBruns-on-console\fR, but can be specified separately for services
  324. that need the console while they start but not afterwards.
  325. This setting is not applicable to regular \fBprocess\fR services, but can be
  326. used for \fBscripted\fR and \fBbgprocess\fR services. It allows for
  327. interrupting startup via the \fIinterrupt\fR key (normally control-C). This is
  328. useful to allow filesystem checks to be interrupted/skipped.
  329. This option is implied by \fBruns\-on\-console\fR, and is mutually exclusive
  330. with \fBshares\-console\fR; setting this option, or setting \fBruns\-on\-console\fR,
  331. unsets \fBshares\-console\fR.
  332. .TP
  333. \fBshares\-console\fR
  334. Specifies that this service should be given access to the console (input and output
  335. will be connected to the console), but that it should not exclusively hold the
  336. console and not delay the start of services with \fBstarts\-on\-console\fR.
  337. This is mutually exclusive with both \fBstarts\-on\-console\fR and \fBruns\-on\-console\fR;
  338. setting this option unsets both those options.
  339. .TP
  340. \fBstarts-rwfs\fR
  341. This service mounts the root filesystem read/write (or at least mounts the
  342. normal writable filesystems for the system). This prompts Dinit to create its
  343. control socket, if it has not already managed to do so.
  344. .TP
  345. \fBstarts-log\fR
  346. This service starts the system log daemon. Dinit will begin logging via the
  347. \fI/dev/log\fR socket.
  348. .TP
  349. \fBpass-cs-fd\fR
  350. Pass an open Dinit control socket to the process when launching it (the
  351. \fIDINIT_CS_FD\fR environment variable will be set to the file descriptor of
  352. the socket). This allows the service to issue commands to Dinit even if the
  353. regular control socket is not available yet.
  354. Using this option has security implications! The service which receives the
  355. control socket must close it before launching any untrusted processes. You
  356. should not use this option unless the service is designed to receive a Dinit
  357. control socket.
  358. .TP
  359. \fBstart-interruptible\fR
  360. This service can have its startup interrupted (cancelled) if it becomes inactive
  361. while still starting, by sending it the SIGINT signal. This is meaningful only
  362. for \fBbgprocess\fR and \fBscripted\fR services.
  363. .TP
  364. \fBskippable\fR
  365. For scripted services, indicates that if the service startup process terminates
  366. via an interrupt signal (SIGINT), then the service should be considered started.
  367. Note that if the interrupt was issued by Dinit to cancel startup, the service
  368. will instead be considered stopped.
  369. .TP
  370. \fBsignal-process-only\fR
  371. Signal the service process only, rather than its entire process group, whenever
  372. sending it a signal for any reason.
  373. .RE
  374. .LP
  375. The next section contains example service descriptions including some of the
  376. parameters and options described above.
  377. .\"
  378. .SS RESOURCE LIMITS
  379. .\"
  380. There are several settings for specifying process resource limits: \fBrlmit-nofile\fR,
  381. \fBrlimit-core\fR, \fBrlimit-data\fR and \fBrlimit-addrspace\fR. See the descriptions
  382. of each above. These settings place a limit on resource usage directly by the process.
  383. Note that resource limits are inherited by subprocesses, but that usage of a resource
  384. and subprocess are counted separately (in other words, a process can effectively bypass
  385. its resource limits by spawning a subprocess and allocating further resources within it).
  386. Resources have both a \fIhard\fR and \fIsoft\fR limit. The soft limit is the effective
  387. limit, but note that a process can raise its soft limit up to the hard limit for any
  388. given resource. Therefore the soft limit acts more as a sanity-check; a process can
  389. exceed the soft limit only by deliberately raising it first.
  390. Resource limits are specified in the following format:
  391. .RS
  392. \fIsoft-limit\fR:\fIhard-limit\fR
  393. .RE
  394. Either the soft limit or the hard limit can be omitted (in which case it will be unchanged).
  395. A limit can be specified as a dash, `\fB-\fR', in which case the limit will be removed. If
  396. only one value is specified with no colon separator, it affects both the soft and hard limit.
  397. .\"
  398. .SS EXAMPLES
  399. .LP
  400. Here is an example service description for the \fBmysql\fR database server.
  401. It has a dependency on the \fBrcboot\fR service (not shown) which is
  402. expected to have set up the system to a level suitable for basic operation.
  403. .RS
  404. .nf
  405. .gcolor blue
  406. .ft CR
  407. # mysqld service
  408. type = process
  409. command = /usr/bin/mysqld --user=mysql
  410. logfile = /var/log/mysqld.log
  411. smooth-recovery = true
  412. restart = false
  413. depends-on = rcboot # Basic system services must be ready
  414. .ft
  415. .gcolor
  416. .RE
  417. .fi
  418. .LP
  419. Here is an examples for a filesystem check "service", run by a script
  420. (\fI/etc/dinit.d/rootfscheck.sh\fR). The script may need to reboot the
  421. system, but the control socket may not have been created, so it uses the
  422. \fBpass-cs-fd\fR option to allow the \fBreboot\fR command to issue control
  423. commands to Dinit. It runs on the console, so that output is visible and
  424. the process can be interrupted using control-C, in which case the check is
  425. skipped but dependent services continue to start.
  426. .RS
  427. .nf
  428. .gcolor blue
  429. .ft CR
  430. # rootfscheck service
  431. type = scripted
  432. command = /etc/dinit.d/rootfscheck.sh
  433. restart = false
  434. options = starts-on-console pass-cs-fd
  435. options = start-interruptible skippable
  436. depends-on = early-filesystems # /proc and /dev
  437. depends-on = device-node-daemon
  438. .ft
  439. .gcolor
  440. .fi
  441. .RE
  442. More examples are provided with the Dinit distribution.
  443. .\"
  444. .SH AUTHOR
  445. Dinit, and this manual, were written by Davin McCall.
  446. $$$dnl