5
# Template and example of a LSB conform init script for the service FOO
6
# See http://www.linuxbase.org/spec/ for details
10
# Required-Start: $syslog $remote_fs
11
# Should-Start: $time $portmap
12
# Required-Stop: $syslog $remote_fs
13
# Should-Stop: $time $portmap
15
# Default-Stop: 0 1 2 6
16
# Short-Description: FOO daemon used for ABC
17
# Description: The FOO service is used for ZZZ
18
# The (long) description can spread multiple lines
19
# which start with '#<TAB>' or # followed by at least
21
# X-UnitedLinux-Default-Enabled: yes
25
# - The LSB actually might be interpreted that there is only a single space
26
# between the the colon after the keyword and the first argument, but
27
# most or all LSB install_initd's support more than one space
28
# - Local extensions start with a X-[LANA registered provider or domain]-
29
# The X-UnitedLinux-Default-Enabled is one of the few actually used
30
# extension (enable service by when installing package, but keep current
31
# status when updating).
33
# The other keywords are described by the LSB. Notes on the differences
34
# between Required-Start and Should-Start (which was introduced by LSB 1.9):
36
# a) Required-Start/Required-Stop is used as hard dependencies, i.e. for
37
# services which have to be started before this service. For instance
38
# needs the 'nfs-kernel-server' the portmap service. Requiring
39
# Required-Start: $portmap
40
# ensures that the portmapper is started before the nfs server.
41
# If a required service is missing, an init script cannot be installed
42
# and an init script which is required by another cannot be removed.
44
# b) Should-Start/Should-Stop is used for weak dependencies. This ensures
45
# that the order of the init scripts is useful. A possible use for
46
# 'autofs' is to ask for
48
# which enables to read maps via NIS. Note that not all LSB install_initd
49
# programs support Should-Start (Debian's does) and therefore one should
50
# try hard not to rely on its support.
52
# The Required-Stop/Should-Stop usually contain the same services as
53
# Required-Start/Should-Start do.
55
# Besides using the services provided by the Provides section of
56
# init script, those predefined facilities are available
57
# (while they start with a $ they are no shell variables):
59
# a) LSB 1.1 facility names
60
# - $local_fs all local filesystems are mounted
61
# - $remote_fs all remote filesystems are mounted
62
# (note that /usr might be remote)
63
# - $syslog system logging is operational
64
# - $network low level networking (ethernet card etc.)
65
# - $named hostname resolution available
66
# - $netdaemons all network daemons are running
67
# (Removed in LSB 1.2)
68
# b) LSB 1.2 facility names
69
# - $time the system time has been set (e.g. NTP)
70
# - $portmap daemons providing SunRPC/ONCRPC portmapping service
73
# The LSB specifies those runlevels, most services use 3 and 5 for
74
# Default-Start and 0 1 2 6 for Default-Stop.
77
# 1 - single user mode
78
# 2 - multiuser with no network services exported
79
# 3 - normal/full multiuser
80
# 4 - reserved for local use (usually normal/full multiuser)
81
# 5 - multiuser with xdm or equivalent
84
# Note on that script names should follow the LSB:
85
# http://www.linuxbase.org/spec/gLSB/gLSB/scrptnames.html
86
# There is a registry for script names that are reserved for use by
87
# distributions and registered script and provider names at
88
# http://www.lanana.org/
90
# Source LSB init functions
91
# This provides start_daemon, killproc, pidofproc,
92
# log_success_msg, log_failure_msg and log_warning_msg.
93
. /lib/lsb/init-functions
95
# Since init scripts are config files, they might be left after an uninstall
96
# Check whether the binary is still present:
98
test -x "$FOO_BIN" || {log_failure_msg "$FOO_BIN not installed"; exit 5}
100
# Check whether a required configuration file is available
101
FOO_CONFIG=/etc/FOO.conf
102
test -r "$FOO_CONFIG" || {log_failure_msg "$FOO_CONFIG not existing"; exit 6}
104
# Those LSB defined exit status codes shall be used (except for status)
106
# 1 generic or unspecified error (current practice)
107
# 2 invalid or excess argument(s)
108
# 3 unimplemented feature (for example, "reload")
109
# 4 user had insufficient privilege
110
# 5 program is not installed
111
# 6 program is not configured
112
# 7 program is not running
113
# 8-199 reserved (8-99 LSB, 100-149 distribution, 150-199 application)
115
# Note that those situation shall also be regarded as success:
116
# * restarting a service (instead of reloading it)
117
# with the "force-reload" argument
118
# * running "start" on a service already running
119
# * running "stop" on a service already stopped or not running
120
# * running "restart" on a service already stopped or not running
121
# * running "try-restart" on a service already stopped or not running
126
# Start service with startproc which shall return the
128
start_daemon "$FOO_BIN" -c "$FOO_CONFIG"
132
log_success_msg "Starting FOO"
134
log_failure_msg "Starting FOO"
139
echo -n "Shutting down FOO "
140
# Stop the service with killproc which shall return the
145
log_success_msg "Shutting down FOO"
148
log_failure_msg "Shutting down FOO"
153
# Do a restart only if the service is running
154
# try-restart has been added to the LSB in 1.9
155
# RedHat's similar command is called condrestart.
156
$0 status > /dev/null
162
log_success_msg "Try-Restarting FOO: not running"
164
exit 0 # not running is also regarded as success
167
# Restart service (if running) or start service
172
# Reload the configuartion. Usually a SIGHUP is used for this
173
# If it doesn't support his signal, restart it (only if running)
175
# Supports signalling
176
killproc -HUP "$FOO_BIN"
180
log_success_msg "Reloading FOO"
182
log_failure_msg "Reloading FOO"
190
# Reload configuration file, but don't restart if it is not supported
192
# If it supports signaling:
193
killproc -HUP "$FOO_BIN"
197
log_success_msg "Reloading FOO"
199
log_failure_msg "Reloading FOO"
207
# Use pidofproc to check the status of the service,
208
# pidofproc returns the exit status code of 0 when it the process is
211
# LSB defined exit status codes for status:
212
# 0 program is running or service is OK
213
# 1 program is dead and /var/run pid file exists
214
# 2 program is dead and /var/lock lock file exists
215
# 3 program is not running
216
# 4 program or service status is unknown
217
# 5-199 reserved (5-99 LSB, 100-149 distribution, 150-199 applications)
219
checkproc "$FOO_BIN" > /dev/null
223
log_success_msg "Checking FOO"
225
log_warning_msg "Checking FOO: Not running"
230
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"