dinit.1 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. .TH DINIT "1" "June 2017" "Dinit 0.06" "Dinit \- service management system"
  2. .SH NAME
  3. dinit \- supervise processes and manage services
  4. .\"
  5. .SH SYNOPSIS
  6. .\"
  7. .B dinit
  8. [\-s] [\-d \fIdir\fR] [\-p \fIpath\fR] [\fIservice-name\fR]
  9. .\"
  10. .SH DESCRIPTION
  11. .\"
  12. \fBDinit\fR is a process supervisor and service manager which can also
  13. function as a system \fBinit\fR process. It has a small but functional
  14. feature set, offering service dependency handling, parallel startup,
  15. automatic rate-limited restart of failing processes, and service control
  16. functions.
  17. .LP
  18. Dinit reads service descriptions from files located in the service
  19. description directory, normally \fI/etc/dinit.d\fR for the system instance
  20. or \fI$HOME/dinit.d\fR when run as a user process. See \fBSERVICE
  21. DESCRIPTION FILES\fR for details.
  22. .\"
  23. .SH OPTIONS
  24. .TP
  25. \fB\-d\fR \fIdir\fP, \fB\-\-services\-dir\fR \fIdir\fP
  26. Specifies \fIdir\fP as the directory containing service definition files.
  27. .TP
  28. \fB\-p\fR \fIpath\fP, \fB\-\-socket-path\fR \fIpath\fP
  29. Species \fIpath\fP as the path to the control socket used to listen for
  30. commands from the \fBdinitctl\fR program.
  31. .TP
  32. \fB\-s\fR, \fB\-\-system\fR
  33. Run as the system init process. This is the default if invoked as PID 1.
  34. This option affects the default service definition directory and
  35. control socket path.
  36. .TP
  37. \fB\-\-help\fR
  38. display this help and exit
  39. .TP
  40. \fIservice-name\fR
  41. Specifies the name of the service that should be started (along with its
  42. dependencies). If not specified, defaults to \fIboot\fR (which requires
  43. that a suitable service description for the \fIboot\fR service exists).
  44. .\"
  45. .SH SERVICE DESCRIPTION FILES
  46. .\"
  47. Service description files specify the various attributes of a service. A
  48. service description file is named after the service it represents, and is
  49. a plain-text file with simple key-value format. The description files are
  50. located in the service description directory (which defaults to
  51. \fI/etc/dinit.d\fR for the system process).
  52. .LP
  53. All services have a \fItype\fR and a set of \fIdependencies\fR. Service
  54. types are discussed in the following subsection. If a service depends on
  55. another service, then starting the first service causes the second to start
  56. also (and the second service must complete its startup before the first
  57. is considered started). Similarly, if one service depends on another which
  58. becomes stopped, the first service must also stop.
  59. .LP
  60. Service description files are read by Dinit on an "as needed" basis. Once a
  61. service description has been read there is no way (yet) to alter it.
  62. .\"
  63. .SS SERVICE TYPES
  64. .\"
  65. There are four basic types of service:
  66. .IP \(bu
  67. \fBProcess\fR services. This kind of service runs as a single process; starting
  68. the service simply requires starting the process; stopping the service is
  69. accomplished by stopping the process (via sending it a signal).
  70. .IP \(bu
  71. \fBBgprocess\fR services ("background process" services). This kind of
  72. service is similar to a regular process service, but the process daemonizes
  73. or otherwise forks from the original process which starts it, and the
  74. process ID is written to a file. Dinit can read the process ID from the
  75. file and, if it is running as the system init process, can supervise it.
  76. .IP \(bu
  77. \fBScripted\fR services are services which are started and stopped by a
  78. command (which need not actually be a script, despite the name). They can
  79. not be supervised.
  80. .IP \(bu
  81. \fBInternal\fR services do not run as an external process at all. They can
  82. be started and stopped without any external action. They are useful for
  83. grouping other services (via service dependencies).
  84. .\"
  85. .SS SERVICE PROPERTIES
  86. .\"
  87. This section described the various service properties that can be specified
  88. in a service description file. Each line of the file can specify a single
  89. property value, expressed as "\fIproperty-name\fR = \fIvalue\fR". Comments
  90. begin with a hash mark (#) and extend to the end of the line (they must be
  91. separated from setting values by at least one whitespace character). Values
  92. are interpreted literally, except that:
  93. .\"
  94. .IP \(bu
  95. White space (comprised of spaces, tabs, etc) is collapsed to a single space.
  96. .IP \(bu
  97. Double quotes (") can be used around all or part of a property value, to
  98. prevent whitespace collapse and prevent interpretation of other special
  99. characters (such as "#") inside the quotes. The quote characters are not
  100. considered part of the parameter value.
  101. .IP \(bu
  102. A backslash (\\) can be used to escape the next character, causing it to
  103. lose any special meaning and become part of the property value. A double
  104. backslash (\\\\) is collapsed to a single backslash within the parameter
  105. value.
  106. .LP
  107. The following properties can be specified:
  108. .TP
  109. \fBtype\fR = {process | bgprocess | scripted | internal}
  110. Specifies the service type.
  111. .TP
  112. \fBcommand\fR = \fIcommand-string\fR
  113. Specifies the command, including command-line arguments, for starting the
  114. process. Applies only to \fBprocess\fR, \fBbgprocess\fR and \fBscripted\fR
  115. services.
  116. .TP
  117. \fBstop\-command\fR = \fIcommand-string\fR
  118. Specifies the command to stop the service. Applicable only to \fBscripted\fR
  119. services.
  120. .TP
  121. \fBrestart\fR = {yes | true | no | false}
  122. Indicates whether the service should automatically restart if it stops for
  123. any reason (including unexpected process termination, service dependency
  124. stopping, or user-initiated service stop).
  125. .TP
  126. \fBsmooth-recovery\fR = {yes | true | no | false}
  127. Applies only to \fBprocess\fR and \fBbgprocess\fR services. When set true/yes,
  128. an automatic process restart can be performed without first stopping any
  129. dependent services. This setting is meaningless if the \fBrestart\fR setting
  130. is set to false.
  131. .TP
  132. \fBrestart-delay\fR = \fIXXX.YYYY\fR
  133. Specifies the minimum time between automatic restarts. Enforcing a sensible
  134. minimum prevents Dinit from consuming a large number of process cycles in
  135. case a process continuously fails immediately after it is started. The
  136. default is 0.2 (200 milliseconds).
  137. .TP
  138. \fBrestart-limit-interval\fR = \fIXXX.YYYY\fR
  139. Sets the interval, in seconds, over which restarts are limited. If a process
  140. automatically restarts more than a certain number of times (specified by the
  141. \fBrestart-limit-count\fR setting) in this time interval, it will not restart
  142. again. The default value is 10 seconds.
  143. .TP
  144. \fBrestart-limit-count\fR = \fINNN\fR
  145. Specifies the maximum number of times that a service can automatically restart
  146. over the interval specified by \fBrestart-limit-interval\fR. Specify a value
  147. of 0 to disable the restart limit.
  148. .TP
  149. \fBpid-file\fR = \fIpath-to-file\fR
  150. For \fBbgprocess\fR type services only; specifies the path of the file where
  151. daemon will write its process ID before detaching. Dinit will read the
  152. contents of this file when starting the service, once the initial process
  153. exits, will supervise the process with the discovered process ID, and may
  154. send signals to the process ID to stop the service; if Dinit runs as a
  155. privileged user the path should therefore not be writable by unprivileged
  156. users.
  157. .TP
  158. \fBdepends-on\fR = \fIservice-name\fR
  159. This service depends on the named service. Starting this service will start
  160. the named service; the command to start this service will not be executed
  161. until the named service has started. If the named service is stopped then
  162. this service will also be stopped.
  163. .TP
  164. \fBwaits-for\fR = \fIservice-name\fR
  165. When this service is started, wait for the named service to finish starting
  166. (or to fail starting) before commencing the start procedure for this service.
  167. Starting this service will automatically start the named service. If the
  168. named service fails to start, this service will start as usual (subject to
  169. other dependencies being met).
  170. .TP
  171. \fBsocket-listen\fR = \fIsocket-path\fR
  172. Pre-open a socket for the service and pass it to the service using the
  173. \fBsystemd\fR activation protocol. This by itself does not give so called
  174. "socket activation", but does allow that any process trying to connect to the
  175. specified socket will be able to do so, even before the service is properly
  176. prepared to accept connections.
  177. .TP
  178. \fBsocket-permissions\fR = \fIoctal-permissions-mask\fR
  179. Gives the permissions for the socket specified using \fBsocket-listen\fR.
  180. Normally this will be 600 (user access only), 660 (user and group
  181. access), or 666 (all users). The default is 666.
  182. .TP
  183. \fBsocket-uid\fR = {\fInumeric-user-id\fR | \fIusername\fR}
  184. Specifies the user that should own the activation socket. If
  185. \fBsocket-uid\fR is specified without also specifying \fBsocket-gid\fR, then
  186. the socket group is the primary group of the specified user (as found in the
  187. system user database, normally \fI/etc/passwd\fR). If the socket owner is not
  188. specified, the socket will be owned by the user id of the Dinit process.
  189. .TP
  190. \fBsocket-gid\fR = {\fInumeric-group-id\fR | \fIgroup-name\fR}
  191. Specifies the group of the activation socket. See discussion of
  192. \fBsocket-uid\fR.
  193. .TP
  194. \fBtermsignal\fR = {HUP | INT | QUIT | USR1 | USR2}
  195. Specifies an additional signal to send to the process when requesting it
  196. to terminate (applies to 'process' services only). SIGTERM is always
  197. sent along with the specified signal, unless the \fBnosigterm\fR option is
  198. specified via the \fBoptions\fR parameter.
  199. .TP
  200. \fBoptions\fR = {runs\-on\-console | nosigterm | starts\-rwfs | starts\-log}...
  201. Specifies various options for this service:
  202. .RS
  203. .TP
  204. \fBno-sigterm\fR
  205. specifies that the TERM signal should not be send to the process to terminate
  206. it. (Another signal can be specified using the \fBtermsignal\fR setting; if no
  207. other signal is specified, no signal will be sent, which usually means that
  208. the service will not terminate).
  209. .TP
  210. \fBruns-on-console\fR
  211. specifies that this service uses the console; its input and output should be
  212. directed to the console (or precisely, to the device to which Dinit's standard
  213. output stream is connected). A service running on the console prevents other
  214. services from running on the console (they will queue for the console).
  215. The \fIinterrupt\fR key (normally control-C) will be active for process / scripted
  216. services that run on the console. Handling of an interrupt is determined by
  217. the service process, but typically will cause it to terminate.
  218. .TP
  219. \fBstarts-on-console\fR
  220. specifies that this service uses the console during service startup. This is
  221. implied by \fBruns-on-console\fR, but can be specified separately for services
  222. that need the console while they start but not afterwards.
  223. This setting is not applicable to regular \fBprocess\fR services, but can be
  224. used for \fBscripted\fR and \fBbgprocess\fR services. It allows for
  225. interrupting startup via the \fIinterrupt\fR key (normally control-C). This is
  226. useful to allow filesystem checks to be interrupted/skipped.
  227. .TP
  228. \fBstarts-rwfs\fR
  229. this service mounts the root filesystem read/write (or at least mounts the
  230. normal writable filesystems for the system). This prompts Dinit to create its
  231. control socket, if it has not already managed to do so.
  232. .TP
  233. \fBstarts-log\fR
  234. this service starts the system log daemon. Dinit will begin logging via the
  235. \fI/dev/log\fR socket.
  236. .TP
  237. \fBpass-cs-fd\fR
  238. pass an open Dinit control socket to the process when launching it (the
  239. \fIDINIT_CS_FD\fR environment variable will be set to the file descriptor of
  240. the socket). This allows the service to issue commands to Dinit even if the
  241. regular control socket is not available yet.
  242. Using this option has security implications! The service which receives the
  243. control socket must close it before launching any untrusted processes. You
  244. should not use this option unless the service is designed to receive a Dinit
  245. control socket.
  246. .RE
  247. .TP
  248. \fBlogfile\fR = \fIlog-file-path\fR
  249. Specifies the log file for the service. Output from the service process
  250. will go this file.
  251. .LP
  252. The next section contains example service descriptions including some of the
  253. parameters and options described above.
  254. .\"
  255. .SS EXAMPLES
  256. .LP
  257. Here is an example service description for the \fBmysql\fR database server.
  258. It has a dependency on the \fBrcboot\fR service (not shown) which is
  259. expected to have set up the system to a level suitable for basic operation.
  260. .RS
  261. .nf
  262. .gcolor yellow
  263. # mysqld service
  264. type = process
  265. command = /usr/bin/mysqld --user=mysql
  266. logfile = /var/log/mysqld.log
  267. smooth-recovery = true
  268. restart = false
  269. depends-on = rcboot # Basic system services must be ready
  270. .gcolor
  271. .RE
  272. .fi
  273. .LP
  274. Here is an examples for a filesystem check "service", run by a script
  275. (\fI/etc/dinit.d/rootfscheck.sh\fR). The script may need to reboot the
  276. system, but the control socket may not have been created, so it uses the
  277. \fBpass-cs-fd\fR option to allow the \fBreboot\fR command to issue control
  278. commands to Dinit. It runs on the console, so that output is visible and
  279. the process can be interrupted using control-C.
  280. .RS
  281. .nf
  282. .gcolor yellow
  283. # rootfscheck service
  284. type = scripted
  285. command = /etc/dinit.d/rootfscheck.sh
  286. restart = false
  287. options = starts-on-console pass-cs-fd
  288. depends-on = early-filesystems # /proc and /dev
  289. depends-on = device-node-daemon
  290. .gcolor
  291. .fi
  292. .RE
  293. More examples are provided with the Dinit distribution.
  294. .\"
  295. .SH SIGNALS
  296. .LP
  297. When run as a system process, SIGINT stops all services and performs a reboot (on Linux, this signal can be
  298. generated using the control-alt-delete key combination); SIGTERM stops services and halts the system; and
  299. SIGQUIT performs an immediate shutdown with no service rollback.
  300. LP
  301. When run as a user process, SIGINT and SIGTERM both stop services and exit Dinit; SIGQUIT exits Dinit
  302. immediately.
  303. .\"
  304. .SH SEE ALSO
  305. .\"
  306. \fBdinitctl\fR(1).
  307. .\"
  308. .SH AUTHOR
  309. Dinit, and this manual, were written by Davin McCall.