Add "smooth-recovery" option for process services.
[oweals/dinit.git] / README
1 Dinit
2 -----
3 v0.1 (pre-release)
4
5
6 What is it?
7 =-=-=-=-=-=
8
9 "Dinit" is a service supervisor with dependency support which can also
10 act as the system "init" program.
11
12 Specifically it can launch multiple services (generally, "daemon" processes,
13 but see notes below) in parallel, with dependency management (i.e. if one
14 service's operation depends on another, the latter service will be started
15 first).
16
17 For "process" services dinit can monitor the process corresponding to the
18 service, and re-start it if it dies. It does this in an intelligent way,
19 first "rolling back" all dependent services (which it will later re-start,
20 if configured to do so).
21
22 Dinit is designed to work on POSIXy operating systems such as Linux and
23 OpenBSD. It is written in C++ and uses the "libev" event handling library.
24 Development goals include clean design, robustness, portability, and
25 avoiding feature bloat (whilst still handling a variety of use cases).
26
27 See doc/COMPARISON for a comparison of Dinit with similar software packages.
28
29 The primary author of Dinit is Davin McCall <davmac@davmac.org>.
30
31
32 Introduction to services
33 =-=-=-=-=-=-=-=-=-=-=-=-
34
35 A "service" is nominally a persistent process or system state. The two main
36 types of service are a _process_ service (represented by a an actual process)
37 and a _scripted_ service (which is started and stopped by running a process -
38 often a shell script - to completion).
39
40 Many programs that you might want to run under dinit's supervision can run
41 either "in the foreground" or as a daemon ("in the background"), and the
42 choice is dictated by a command line switch (for instance the -D and -F
43 switches to Samba's "smbd"). Although it might seem counterintuitive,
44 the "foreground" mode should be used for programs registered as process
45 services in dinit; this allows dinit to monitor the process.
46
47 Process services are attractive due to the ease of monitoring (and
48 restarting) the service, however, they have one inherent problem, which is
49 that dinit cannot tell when the service is truly started. Once the process
50 has been launched, dinit assumes that the service has started, but in fact
51 there will be a short delay before the process sets itself up, starts
52 listening on sockets, etc; during this time any other process (including
53 one from a service listed as dependent) which tries to contact it will not
54 be able to do so. In practice, this is not usually a problem (and external
55 solutions, like D-Bus, do exist).
56
57
58
59 Service Description files
60 =-=-=-=-=-=-=-=-=-=-=-=-=
61
62 Dinit discovers services by reading _service description files_. These files
63 reside in a directory (/etc/dinit.d is the default "system" location) and
64 their name matches the name of the service. Service descriptions are loaded
65 lazily, as needed by Dinit.
66
67 A service description file consists of a number of parameter settings.
68 Settings in the SDF are denoted as a parameter name followed by either an
69 equal sign or colon and then the parameter value (all on the same line).
70 Comments begin with a hash mark (#) and extend to the end of the line.
71
72 Parameter values are interpreted literally, except that:
73  - whitespace is collapsed to a single space
74  - double quotes can be used around all or part(s) of a parameter to prevent
75    whitespace collapse and interpretation of special characters
76  - backslash can be used to 'escape' the next character, preventing any
77    special meaning from being associated with it. It can be used to include
78    non-collapsing whitespace, double-quote marks, and backslashes in the
79    parameter value.
80
81 Parameters are:
82
83 type = process | scripted | internal
84 command = ...
85 logfile = ...
86 onstart = ...
87 depends-on = (service name)
88 waits-for = (service name)
89
90 command = (external script or executable, and arguments)
91    For a 'process' service, this is the process to run.
92    For a 'scripted' service, this command is run to start the service.
93
94 stop-command = (external script or executable, and arguments)
95    For a 'scripted' service, this command is run to stop the service.
96
97 restart = yes | true | no | false
98    Specifies whether the service should automatically restart if it becomes
99    stopped (for any reason, including being explicitly requested to stop).
100
101 smooth-recovery = yes | true | no | false
102    For process services only. Specifies that, should the process die, it
103    can be restarted without bringing the service itself down. This means that
104    any dependent services do not need to be stopped/restarted. Such recovery
105    happens regardless of the "restart" setting (if smooth-recovery is enabled,
106    the service does not reach the stopped state when the process terminates
107    unexpectedly).
108
109 onstart = (internal commands)
110    rw_ready - try again to open any logs, control socket etc that could not
111               be opened previously due to a read-only filesystem.
112
113 depends-on = (service name)
114    This service depends on the named service. Starting this service will
115    start the named service; the command to start this service will not be
116    executed until the named service has started. If the named service is
117    stopped then this service will also be stopped.
118
119 waits-for = (service name)
120    When this service is started, wait for the named service to finish
121    starting (or to fail starting) before commencing the start procedure
122    for this service. Starting this service will automatically start
123    the named service.
124
125 termsignal = HUP | INT | QUIT | USR1 | USR2
126    Specifies an additional signal to send to the process when requesting it
127    to terminate (applies to 'process' services only). SIGTERM is always
128    sent along with the specified signal, unless the 'nosigterm' setting is
129    set true.
130
131 nosigterm = yes | true | no | false
132    If true, the TERM signal will not be sent to the process to kill it. (If
133    an alternate signal is specified using the "termsignal" setting, that
134    signal will be sent instead; otherwise, no signal will be sent, and the
135    process must be killed by external means).
136
137 runs-on-console = yes | no | true | false
138   If true, the service runs on the console; its input and output are
139   directed to the console (actually, to the terminal on which Dinit is
140   running) and Dinit's own output will be suppressed during this time.
141   Control signals (^C) may be used to control a service running on the
142   console.
143
144   This is useful to allow a "login" master service to prevent Dinit output
145   once terminal sessions are spawned, or to make fsck display its progress
146   on the terminal (and be interruptible).
147
148   Only one service can run on the console at a time (services will queue
149   in order to gain access to the console).
150
151   For scripted services, only the start command runs on the console.
152   Process services and internal services take the console for the entire
153   time that they are active (and cannot release it).
154