4a477a86cf5030c73631fd7e865e14cfa69c1b7f
[oweals/dinit.git] / doc / manpages / dinit.8
1 .TH DINIT "8" "June 2017" "Dinit 0.07" "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 \fBstart-timeout\fR = \fIXXX.YYY\fR
150 Specifies the time in seconds allowed for the service to start. If the
151 service takes longer than this, its process group is sent a SIGINT signal
152 and enters the "stopping" state (this may be subject to a stop timeout, as
153 specified via \fBstop-timeout\fR, after which the process group will be
154 terminated via SIGKILL). The timeout period begins only when all dependencies
155 have been stopped. The default timeout is 60 seconds. Specify a value of 0 to
156 allow unlimited start time.
157 .TP
158 \fBstop-timeout\fR = \fIXXX.YYY\fR
159 Specifies the time in seconds allowed for the service to stop. If the
160 service takes longer than this, its process group is sent a SIGKILL signal
161 which should cause it to terminate immediately. The timeout period begins
162 only when all dependent services have already stopped. The default
163 timeout is 10 seconds. Specify a value of 0 to allow unlimited stop time.
164 .TP
165 \fBpid-file\fR = \fIpath-to-file\fR
166 For \fBbgprocess\fR type services only; specifies the path of the file where
167 daemon will write its process ID before detaching. Dinit will read the
168 contents of this file when starting the service, once the initial process
169 exits, will supervise the process with the discovered process ID, and may
170 send signals to the process ID to stop the service; if Dinit runs as a
171 privileged user the path should therefore not be writable by unprivileged
172 users.
173 .TP
174 \fBdepends-on\fR = \fIservice-name\fR
175 This service depends on the named service. Starting this service will start
176 the named service; the command to start this service will not be executed
177 until the named service has started. If the named service is stopped then
178 this service will also be stopped.
179 .TP
180 \fBdepends-ms\fR = \fIservice-name\fR
181 This service has a "milestone" dependcy on the named service. Starting this
182 service will start the named service; the command to start this service will
183 not be executed until the named service has started. If the named service is
184 stopped then the dependency is dropped until this service is next started.
185 .TP
186 \fBwaits-for\fR = \fIservice-name\fR
187 When this service is started, wait for the named service to finish starting
188 (or to fail starting) before commencing the start procedure for this service.
189 Starting this service will automatically start the named service. If the
190 named service fails to start, this service will start as usual (subject to
191 other dependencies being met).
192 .TP
193 \fBsocket-listen\fR = \fIsocket-path\fR
194 Pre-open a socket for the service and pass it to the service using the
195 \fBsystemd\fR activation protocol. This by itself does not give so called
196 "socket activation", but does allow that any process trying to connect to the
197 specified socket will be able to do so, even before the service is properly
198 prepared to accept connections.
199 .TP
200 \fBsocket-permissions\fR = \fIoctal-permissions-mask\fR
201 Gives the permissions for the socket specified using \fBsocket-listen\fR.
202 Normally this will be 600 (user access only), 660 (user and group
203 access), or 666 (all users). The default is 666.
204 .TP
205 \fBsocket-uid\fR = {\fInumeric-user-id\fR | \fIusername\fR}
206 Specifies the user that should own the activation socket. If
207 \fBsocket-uid\fR is specified without also specifying \fBsocket-gid\fR, then
208 the socket group is the primary group of the specified user (as found in the
209 system user database, normally \fI/etc/passwd\fR). If the socket owner is not
210 specified, the socket will be owned by the user id of the Dinit process.
211 .TP
212 \fBsocket-gid\fR = {\fInumeric-group-id\fR | \fIgroup-name\fR}
213 Specifies the group of the activation socket. See discussion of
214 \fBsocket-uid\fR.
215 .TP
216 \fBtermsignal\fR = {HUP | INT | QUIT | USR1 | USR2}
217 Specifies an additional signal to send to the process when requesting it
218 to terminate (applies to 'process' services only). SIGTERM is always
219 sent along with the specified signal, unless the \fBnosigterm\fR option is
220 specified via the \fBoptions\fR parameter.
221 .TP
222 \fBoptions\fR = {runs\-on\-console | nosigterm | starts\-rwfs | starts\-log | start\-interruptible}...
223 Specifies various options for this service:
224 .RS
225 .TP
226 \fBno-sigterm\fR
227 specifies that the TERM signal should not be send to the process to terminate
228 it. (Another signal can be specified using the \fBtermsignal\fR setting; if no
229 other signal is specified, no signal will be sent, which usually means that
230 the service will not terminate).
231 .TP
232 \fBruns-on-console\fR
233 specifies that this service uses the console; its input and output should be
234 directed to the console (or precisely, to the device to which Dinit's standard
235 output stream is connected). A service running on the console prevents other
236 services from running on the console (they will queue for the console).
237
238 The \fIinterrupt\fR key (normally control-C) will be active for process / scripted
239 services that run on the console. Handling of an interrupt is determined by
240 the service process, but typically will cause it to terminate.
241 .TP
242 \fBstarts-on-console\fR
243 specifies that this service uses the console during service startup. This is
244 implied by \fBruns-on-console\fR, but can be specified separately for services
245 that need the console while they start but not afterwards.
246
247 This setting is not applicable to regular \fBprocess\fR services, but can be
248 used for \fBscripted\fR and \fBbgprocess\fR services. It allows for
249 interrupting startup via the \fIinterrupt\fR key (normally control-C). This is
250 useful to allow filesystem checks to be interrupted/skipped.
251 .TP
252 \fBstarts-rwfs\fR
253 this service mounts the root filesystem read/write (or at least mounts the
254 normal writable filesystems for the system). This prompts Dinit to create its
255 control socket, if it has not already managed to do so.
256 .TP
257 \fBstarts-log\fR
258 this service starts the system log daemon. Dinit will begin logging via the
259 \fI/dev/log\fR socket.
260 .TP
261 \fBpass-cs-fd\fR
262 pass an open Dinit control socket to the process when launching it (the
263 \fIDINIT_CS_FD\fR environment variable will be set to the file descriptor of
264 the socket). This allows the service to issue commands to Dinit even if the
265 regular control socket is not available yet.
266
267 Using this option has security implications! The service which receives the
268 control socket must close it before launching any untrusted processes. You
269 should not use this option unless the service is designed to receive a Dinit
270 control socket.
271 .TP
272 \fBstart-interruptible\fR
273 this service can have its startup interrupted (cancelled) if it becomes inactive
274 while still starting, by sending it the SIGINT signal. This is meaningful only
275 for \fBbgprocess\fR and \fBscripted\fR services.
276 .RE
277 .TP
278 \fBlogfile\fR = \fIlog-file-path\fR
279 Specifies the log file for the service. Output from the service process
280 will go this file.
281 .LP
282 The next section contains example service descriptions including some of the
283 parameters and options described above.
284 .\"
285 .SS EXAMPLES
286 .LP
287 Here is an example service description for the \fBmysql\fR database server.
288 It has a dependency on the \fBrcboot\fR service (not shown) which is
289 expected to have set up the system to a level suitable for basic operation.
290
291 .RS
292 .nf
293 .gcolor blue
294 .ft CR
295 # mysqld service
296 type = process
297 command = /usr/bin/mysqld --user=mysql
298 logfile = /var/log/mysqld.log
299 smooth-recovery = true
300 restart = false
301 depends-on = rcboot # Basic system services must be ready
302 .ft
303 .gcolor
304 .RE
305 .fi
306 .LP
307 Here is an examples for a filesystem check "service", run by a script
308 (\fI/etc/dinit.d/rootfscheck.sh\fR). The script may need to reboot the
309 system, but the control socket may not have been created, so it uses the
310 \fBpass-cs-fd\fR option to allow the \fBreboot\fR command to issue control
311 commands to Dinit. It runs on the console, so that output is visible and
312 the process can be interrupted using control-C.
313
314 .RS
315 .nf
316 .gcolor blue
317 .ft CR
318 # rootfscheck service
319 type = scripted
320 command = /etc/dinit.d/rootfscheck.sh
321 restart = false
322 options = starts-on-console pass-cs-fd
323 depends-on = early-filesystems  # /proc and /dev
324 depends-on = device-node-daemon
325 .ft
326 .gcolor
327 .fi
328 .RE
329
330 More examples are provided with the Dinit distribution.
331 .\"
332 .SH SIGNALS
333 .LP
334 When run as a system process, SIGINT stops all services and performs a reboot (on Linux, this signal can be
335 generated using the control-alt-delete key combination); SIGTERM stops services and halts the system; and
336 SIGQUIT performs an immediate shutdown with no service rollback.
337 .LP
338 When run as a user process, SIGINT and SIGTERM both stop services and exit Dinit; SIGQUIT exits Dinit
339 immediately.
340 .\"
341 .SH SEE ALSO
342 .\"
343 \fBdinitctl\fR(8).
344 .\"
345 .SH AUTHOR
346 Dinit, and this manual, were written by Davin McCall.