File: init-d-script.5

package info (click to toggle)
sysvinit 3.15-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,900 kB
  • sloc: ansic: 8,530; sh: 3,827; makefile: 351
file content (209 lines) | stat: -rw-r--r-- 5,408 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
.Dd September 3, 2024
.Dt INIT\-D\-SCRIPT 5 "Debian sysvinit"
.Os Debian
.Sh NAME
.Nm init\-d\-script
.Nd interpreter for short and simple init.d scripts
.Sh DESCRIPTION
Generic init.d script framework to reduce the redundant code in
.Pa /etc/init.d/ .
The goal is to create an init.d script that is Debian and LSB compliant.
When the Debian policy conflicts with the LSB, the Debian policy takes
precedence.
.Pp
This is a simple example on how init\-d\-script can be used to start
and stop a daemon with PID file support:
.Bd -literal -offset indent
#!/bin/sh /lib/init/init\-d\-script
### BEGIN INIT INFO
# Provides:          atd
# Required\-Start:    $syslog $time $remote_fs
# Required\-Stop:     $syslog $time $remote_fs
# Default\-Start:     2 3 4 5
# Default\-Stop:      0 1 6
# Short\-Description: run at jobs
# Description:       Debian init script to start the daemon
#                    running at jobs.
### END INIT INFO
DAEMON=/usr/sbin/atd
.Ed
.Pp
The following variables affect behaviour of an init script:
.Bl -tag -width "RELOAD_SIGNAL"
.It Ev DAEMON
Path to daemon being started.
If the init script is not supposed to start any kind of daemon,
it should be set to
.Dq Li none
and the functions
.Fn do_start_override ,
.Fn do_stop_override
and
.Fn do_status_override
should be defined instead.
.It Ev DAEMON_ARGS
Additional arguments, passed to daemon during start.
.It Ev DESC
Full name or short description of the daemon, printed on screen.
If unset, this variable defaults to the
.Dq Ev NAME
value.
.It Ev NAME
Additional environment variables are sourced from
.Pa /etc/default/${NAME}
and made available to executed processes and within overridden functions,
but not at top level.
If unset, this variable defaults to the basename of the
.Dq Ev DAEMON
value.
.It Ev COMMAND_NAME
If this variable is set, it is used as argument to the
.Fl \-name
option of
.Xr start\-stop\-daemon 8 .
It may be useful if the value of the
.Dq Ev NAME
variable is longer than the command name length supported by
the running kernel.
If the value is verbatim
.Dq Li none ,
the command name will not be used to match the processes.
If unset, this variable defaults to the
.Dq Ev NAME
value.
.It Ev TYPE
If this variable is set to
.Dq Li oneshot ,
experimental support for a oneshot service is enabled.
.It Ev PIDFILE
Path to file where the process identifier of the started daemon
will be stored during start.
If the value is verbatim
.Dq Li none ,
the process identifier will not be stored in any file.
If this variable is not set, it gets a sensible default value,
so it is rarely necessary to set this variable explicitly.
.It Ev SETPRIV_ARGS
If this directive is set and
.Xr setpriv 1
is available, the invocation of
.Xr start\-stop\-daemon 8
is wrapped in a call to
.Xr setpriv 1
with the specified arguments. Note that the
.Fl \-chuid
argument to
.Xr start\-stop\-daemon 8
requires CAP_SETUID and CAP_SETGID in the bounding capabilities set.
.It Ev RELOAD_SIGNAL
Signal number or name (without the SIG prefix) that will be sent to
the process on
.Ic reload .
If the daemon performs reload action upon receiving a
.Dv SIGHUP
signal, this variable should be set to
.Dq Li 1
or
.Dq Li HUP .
.El
.Pp
The variables
.Ev RELOAD_ARGS ,
.Ev START_ARGS
and
.Ev STOP_ARGS
are additional arguments, passed to
.Xr start\-stop\-daemon 8
during reload, start and stop actions, to override the default options.
.Pp
Additionally, it is possible to change the behaviour of the resulting
shell script by overriding some of the internal functions.
To do so, define function with an
.Ic _override
suffix.
So, for example, to override the
.Fn do_status
function, one should define a
.Fn do_status_override
function.
The
.Em exception
to this rule is the
.Fn do_reload
function, whose override should be defined as-is,
.Em without
the above-mentioned suffix.
.Pp
Here is a control flow chart that explains what functions are called and when:
.Bd -literal -offset indent
/etc/init.d/script start
  do_start
    do_start_prepare # no-op
    do_start_cmd     # start\-stop\-daemon is called here
    do_start_cleanup # no-op

/etc/init.d/script stop
  do_stop
    do_stop_prepare # no-op
    do_stop_cmd     # start\-stop\-daemon is called here
    do_stop_cleanup # no-op

/etc/init.d/script status
  do_status

/etc/init.d/script reload
  do_reload
    do_usage
    exit 3

/etc/init.d/script force\-reload
  do_force_reload
    do_reload   # if overridden
    do_restart
      do_restart_prepare
      do_stop_cmd
      do_start_cmd
      do_restart_cleanup

/etc/init.d/script restart
  do_force_restart
/etc/init.d/script try\-restart
  if do_status; then
    do_restart
      do_restart_prepare
      do_stop_cmd  # start\-stop\-daemon is called here
      do_start_cmd # start\-stop\-daemon is called here
      do_restart_cleanup

/etc/init.d/script \*(Ltarg\*(Gt
  do_unknown \*(Ltarg\*(Gt
    exit 3

/etc/init.d/script
  do_usage
.Ed
.Pp
As can be seen, by default, the script does not support the
.Ic reload
action; it should be implemented by the script writer by defining a
.Fn do_reload
function.
.Pp
If
.Fn do_reload
is not defined but
.Fn do_reload_cmd
is, the latter will be called on
.Ic reload ,
after
.Fn do_reload_prepare
and before
.Fn do_reload_cleanup .
.Sh SEE ALSO
.Xr inittab 8 ,
.Xr service 8 ,
.Xr setpriv 1 ,
.Xr update\-rc.d 8 .
.Sh AUTHORS
.An -nosplit
.An Petter Reinholdtsen Aq pere@debian.org