~ubuntu-branches/ubuntu/raring/lsb/raring-proposed

« back to all changes in this revision

Viewing changes to test/init-skeleton

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-11-02 23:48:49 UTC
  • mfrom: (1.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20081102234849-ixekjvk0kgtqmjuk
Tags: 3.2-20ubuntu1
* Resynchronise with Debian (cups dependency change fixes LP: #279345).
  Remaining changes:
  - Don't conflict with python (>= 2.6).
  - Depend on postfix rather than exim4 as preferred mail-transport-agent
    alternative.
  - Depend on libgl1-mesa-glx rather than libgl1-mesa as preferred libgl1
    alternative.
  - Add Ubuntu logging functions.
* Revert some apparently unintentional dependency changes on the Ubuntu
  side of the merge: move libncurses5 and libpam0g dependencies back from
  lsb-base to lsb-core; set lsb's dependencies on lsb-printing,
  lsb-multimedia, and lsb-languages back to suggestions; and remove lsb's
  suggestion of lsb-qt4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# /etc/init.d/FOO
 
4
#
 
5
# Template and example of a LSB conform init script for the service FOO
 
6
# See http://www.linuxbase.org/spec/ for details
 
7
#
 
8
### BEGIN INIT INFO
 
9
# Provides:          FOO
 
10
# Required-Start:    $syslog $remote_fs
 
11
# Should-Start:      $time $portmap
 
12
# Required-Stop:     $syslog $remote_fs
 
13
# Should-Stop:       $time $portmap
 
14
# Default-Start:     3 5
 
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
 
20
#       two spaces.
 
21
# X-UnitedLinux-Default-Enabled: yes
 
22
### END INIT INFO
 
23
 
24
# Remarks:
 
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).
 
32
#
 
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):
 
35
#
 
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.
 
43
#
 
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
 
47
#      Should-Start: nis
 
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.
 
51
#
 
52
#    The Required-Stop/Should-Stop usually contain the same services as
 
53
#    Required-Start/Should-Start do.
 
54
#
 
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):
 
58
#
 
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
 
71
#                   are running
 
72
#
 
73
# The LSB specifies those runlevels, most services use 3 and 5 for
 
74
# Default-Start and 0 1 2 6 for Default-Stop.
 
75
 
76
# 0 - halt
 
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
 
82
# 6 - reboot
 
83
 
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/
 
89
 
 
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
 
94
 
 
95
# Since init scripts are config files, they might be left after an uninstall
 
96
# Check whether the binary is still present:
 
97
FOO_BIN=/usr/sbin/FOO
 
98
test -x "$FOO_BIN" || {log_failure_msg "$FOO_BIN not installed"; exit 5}
 
99
 
 
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}
 
103
 
 
104
# Those LSB defined exit status codes shall be used (except for status)
 
105
# 0     sucess
 
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)
 
114
 
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
 
122
#
 
123
 
 
124
case "$1" in
 
125
    start)
 
126
        # Start service with startproc which shall return the
 
127
        # LSB exit status
 
128
        start_daemon "$FOO_BIN" -c "$FOO_CONFIG"
 
129
        STATUS=$?
 
130
        if [ "$STATUS" = 0 ]
 
131
        then
 
132
            log_success_msg "Starting FOO"
 
133
        else
 
134
            log_failure_msg "Starting FOO"
 
135
        fi
 
136
        exit $STATUS
 
137
        ;;
 
138
    stop)
 
139
        echo -n "Shutting down FOO "
 
140
        # Stop the service with killproc which shall return the
 
141
        # LSB exit status
 
142
        killproc "$FOO_BIN"
 
143
        STATUS=$?
 
144
        if [ "$STATUS" = 0 ]
 
145
            log_success_msg "Shutting down FOO"
 
146
            exit 0
 
147
        else
 
148
            log_failure_msg "Shutting down FOO"
 
149
        fi
 
150
        exit $STATUS
 
151
        ;;
 
152
    try-restart)
 
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
 
157
        STATUS=$?
 
158
        if [ "$STATUS" = 0 ]
 
159
        then
 
160
            $0 restart
 
161
        else
 
162
            log_success_msg "Try-Restarting FOO: not running"
 
163
        fi
 
164
        exit 0 # not running is also regarded as success
 
165
        ;;
 
166
    restart)
 
167
        # Restart service (if running) or start service
 
168
        $0 stop
 
169
        $0 start
 
170
        ;;
 
171
    force-reload)
 
172
        # Reload the configuartion. Usually a SIGHUP is used for this
 
173
        # If it doesn't support his signal, restart it (only if running)
 
174
 
 
175
        # Supports signalling
 
176
        killproc -HUP "$FOO_BIN"
 
177
        SIGNAL=$?
 
178
        if [ "$SIGNAL" = 0 ]
 
179
        then
 
180
            log_success_msg "Reloading FOO"
 
181
        else
 
182
            log_failure_msg "Reloading FOO"
 
183
        fi
 
184
        exit $STATUS
 
185
 
 
186
        # Otherwise
 
187
        #$0 try-restart
 
188
        ;;
 
189
    reload)
 
190
        # Reload configuration file, but don't restart if it is not supported
 
191
 
 
192
        # If it supports signaling:
 
193
        killproc -HUP "$FOO_BIN"
 
194
        SIGNAL=$?
 
195
        if [ "$SIGNAL" = 0 ]
 
196
        then
 
197
            log_success_msg "Reloading FOO"
 
198
        else
 
199
            log_failure_msg "Reloading FOO"
 
200
        fi
 
201
        exit $STATUS
 
202
        
 
203
        # Otherwise
 
204
        # exit 3
 
205
        ;;
 
206
    status)
 
207
        # Use pidofproc to check the status of the service,
 
208
        # pidofproc returns the exit status code of 0 when it the process is
 
209
        # running.
 
210
 
 
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)
 
218
        
 
219
        checkproc "$FOO_BIN" > /dev/null
 
220
        STATUS=$?
 
221
        if [ "$SIGNAL" = 0 ]
 
222
        then
 
223
            log_success_msg "Checking FOO"
 
224
        else
 
225
            log_warning_msg "Checking FOO: Not running"
 
226
        fi
 
227
        exit $STATUS
 
228
        ;;
 
229
    *)
 
230
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
 
231
        exit 1
 
232
        ;;
 
233
esac