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