Debian Codegraph @

rxstack.init.d.in

raw
1 #!/bin/bash
2 #
3 # Template LSB system startup script for example service/daemon RXSTACK
4 # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
5 #
6 # This library is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation; either version 2.1 of the License, or (at
9 # your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #
20 # /etc/init.d/rxstack
21 # LSB compatible service control script; see http://www.linuxbase.org/spec/
22 # Please send feedback to http://www.suse.de/feedback/
23 #
24 # Note: This template uses functions rc_XXX defined in /etc/rc.status on
25 # UnitedLinux/SUSE/Novell based Linux distributions. However, it will work
26 # on other distributions as well, by using the LSB (Linux Standard Base)
27 # or RH functions or by open coding the needed functions.
28 # Read http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/ if you prefer not
29 # to use this template.
30 #
31 # chkconfig: 345 99 00
32 # description: RXSTACK XYZ daemon providing ZYX
33 #
34 ### BEGIN INIT INFO
35 # Provides: rxstack
36 # Required-Start: $network $local_fs
37 # Should-Start: $network $local_fs
38 # Required-Stop: $network $local_fs
39 # Should-Stop:
40 # Default-Start: 3 5
41 # Default-Stop: 0 1 2 6
42 # Short-Description: rxstack daemon providing access to Regina-REXX queues
43 # Description: Start rxstack to allow Regina REXX programs
44 # to manipulate external queues
45 ### END INIT INFO
46 #
47 # Any extensions to the keywords given above should be preceeded by
48 # X-VendorTag- according to LSB.
49 #
50 # Notes on Required-Start/Should-Start:
51 # * There are two different issues that are solved by Required-Start
52 # and Should-Start
53 # (a) Hard dependencies: This is used by the runlevel editor to determine
54 # which services absolutely need to be started to make the start of
55 # this service make sense. Example: nfsserver should have
56 # Required-Start: $portmap
57 # Also, required services are started before the dependent ones.
58 # The runlevel editor will warn about such missing hard dependencies
59 # and suggest enabling. During system startup, you may expect an error,
60 # if the dependency is not fulfilled.
61 # (b) Specifying the init script ordering, not real (hard) dependencies.
62 # This is needed by insserv to determine which service should be
63 # started first (and at a later stage what services can be started
64 # in parallel). The tag Should-Start: is used for this.
65 # It tells, that if a service is available, it should be started
66 # before. If not, never mind.
67 # * When specifying hard dependencies or ordering requirements, you can
68 # use names of services (contents of their Provides: section)
69 # or pseudo names starting with a $. The following ones are available
70 # according to LSB (1.1):
71 # $local_fs all local file systems are mounted
72 # (most services should need this!)
73 # $remote_fs all remote file systems are mounted
74 # (note that /usr may be remote, so
75 # many services should Require this!)
76 # $syslog system logging facility up
77 # $network low level networking (eth card, ...)
78 # $named hostname resolution available
79 # $netdaemons all network daemons are running
80 # The $netdaemons pseudo service has been removed in LSB 1.2.
81 # For now, we still offer it for backward compatibility.
82 # These are new (LSB 1.2):
83 # $time the system time has been set correctly
84 # $portmap SunRPC portmapping service available
85 # UnitedLinux/SUSE/Novell extensions:
86 # $ALL indicates that a script should be inserted
87 # at the end
88 # * The services specified in the stop tags
89 # (Required-Stop/Should-Stop)
90 # specify which services need to be still running when this service
91 # is shut down. Often the entries there are just copies or a subset
92 # from the respective start tag.
93 # * Should-Start/Stop are now part of LSB as of 2.0,
94 # formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
95 # insserv does support both variants.
96 # * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
97 # (%fillup_and_insserv macro in %post of many RPMs) to specify whether
98 # a startup script should default to be enabled after installation.
99 #
100 # Note on runlevels:
101 # 0 - halt/poweroff 6 - reboot
102 # 1 - single user 2 - multiuser without network exported
103 # 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm)
104 #
105 # Note on script names:
106 # http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
107 # A registry has been set up to manage the init script namespace.
108 # http://www.lanana.org/
109 # Please use the names already registered or register one or use a
110 # vendor prefix.
111
112
113 # Check for missing binaries (stale symlinks should not happen)
114 # Note: Special treatment of stop for LSB conformance
115 RXSTACK_BIN=@prefix@/bin/rxstack
116 RXSTACK_ARGS="-d"
117 test -x $RXSTACK_BIN || { echo "$RXSTACK_BIN not installed";
118 if [ "$1" = "stop" ]; then exit 0;
119 else exit 5; fi; }
120
121 # Check for existence of needed config file and read it
122 #RXSTACK_CONFIG=/etc/sysconfig/rxstack
123 #test -r $RXSTACK_CONFIG || { echo "$RXSTACK_CONFIG not existing";
124 # if [ "$1" = "stop" ]; then exit 0;
125 # else exit 6; fi; }
126
127 # Read config
128 #. $RXSTACK_CONFIG
129
130 # Some variables
131 RXSTACK_PIDFILE=/var/run/rxstack.pid
132
133 # Source LSB init functions
134 # providing start_daemon, killproc, pidofproc,
135 # log_success_msg, log_failure_msg and log_warning_msg.
136 # This is currently not used by UnitedLinux based distributions and
137 # not needed for init scripts for UnitedLinux only. If it is used,
138 # the functions from rc.status should not be sourced or used.
139 #. /lib/lsb/init-functions
140
141 # Shell functions sourced from /etc/rc.status:
142 # rc_check check and set local and overall rc status
143 # rc_status check and set local and overall rc status
144 # rc_status -v be verbose in local rc status and clear it afterwards
145 # rc_status -v -r ditto and clear both the local and overall rc status
146 # rc_status -s display "skipped" and exit with status 3
147 # rc_status -u display "unused" and exit with status 3
148 # rc_failed set local and overall rc status to failed
149 # rc_failed <num> set local and overall rc status to <num>
150 # rc_reset clear both the local and overall rc status
151 # rc_exit exit appropriate to overall rc status
152 # rc_active checks whether a service is activated by symlinks
153
154 # Use the SUSE rc_ init script functions;
155 # emulate them on LSB, RH and other systems
156
157 # Default: Assume sysvinit binaries exist
158 start_daemon() { /sbin/start_daemon ${1+"$@"}; }
159 killproc() { /sbin/killproc ${1+"$@"}; }
160 pidofproc() { /sbin/pidofproc ${1+"$@"}; }
161 checkproc() { /sbin/checkproc ${1+"$@"}; }
162 if test -e /etc/rc.status; then
163 # SUSE rc script library
164 . /etc/rc.status
165 else
166 export LC_ALL=POSIX
167 _cmd=$1
168 declare -a _SMSG
169 if test "${_cmd}" = "status"; then
170 _SMSG=(running dead dead unused unknown reserved)
171 _RC_UNUSED=3
172 else
173 _SMSG=(done failed failed missed failed skipped unused failed failed reserved)
174 _RC_UNUSED=6
175 fi
176 if test -e /lib/lsb/init-functions; then
177 # LSB
178 . /lib/lsb/init-functions
179 echo_rc()
180 {
181 if test ${_RC_RV} = 0; then
182 log_success_msg " [${_SMSG[${_RC_RV}]}] "
183 else
184 log_failure_msg " [${_SMSG[${_RC_RV}]}] "
185 fi
186 }
187 # TODO: Add checking for lockfiles
188 checkproc() { pidofproc ${1+"$@"} >/dev/null 2>&1; return $?; }
189 elif test -e /etc/init.d/functions; then
190 # RHAT
191 . /etc/init.d/functions
192 echo_rc()
193 {
194 #echo -n " [${_SMSG[${_RC_RV}]}] "
195 if test ${_RC_RV} = 0; then
196 success " [${_SMSG[${_RC_RV}]}] "
197 else
198 failure " [${_SMSG[${_RC_RV}]}] "
199 fi
200 }
201 checkproc() { status ${1+"$@"}; return $?; }
202 start_daemon() { daemon ${1+"$@"}; return $?; }
203 else
204 # emulate it
205 echo_rc() { echo " [${_SMSG[${_RC_RV}]}] "; }
206 fi
207 rc_reset() { _RC_RV=0; }
208 rc_failed()
209 {
210 if test -z "$1"; then
211 _RC_RV=1;
212 elif test "$1" != "0"; then
213 _RC_RV=$1;
214 fi
215 return ${_RC_RV}
216 }
217 rc_check()
218 {
219 return rc_failed $?
220 }
221 rc_status()
222 {
223 rc_failed $?
224 if test "$1" = "-r"; then _RC_RV=0; shift; fi
225 if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
226 if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
227 if test "$1" = "-v"; then echo_rc; shift; fi
228 if test "$1" = "-r"; then _RC_RV=0; shift; fi
229 return ${_RC_RV}
230 }
231 rc_exit() { exit ${_RC_RV}; }
232 rc_active()
233 {
234 if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
235 if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
236 return 1
237 }
238 fi
239
240 # Reset status of this service
241 rc_reset
242
243 # Return values acc. to LSB for all commands but status:
244 # 0 - success
245 # 1 - generic or unspecified error
246 # 2 - invalid or excess argument(s)
247 # 3 - unimplemented feature (e.g. "reload")
248 # 4 - user had insufficient privileges
249 # 5 - program is not installed
250 # 6 - program is not configured
251 # 7 - program is not running
252 # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
253 #
254 # Note that starting an already running service, stopping
255 # or restarting a not-running service as well as the restart
256 # with force-reload (in case signaling is not supported) are
257 # considered a success.
258
259 case "$1" in
260 start)
261 echo -n "Starting RXSTACK "
262 ## Start daemon with startproc(8). If this fails
263 ## the return value is set appropriately by startproc.
264 start_daemon $RXSTACK_BIN $RXSTACK_ARGS
265
266 ## Remember status and be verbose
267 rc_status -v
268
269 ## Update PIDFILE if not automatically written
270 pidofproc $RXSTACK_BIN > $RXSTACK_PIDFILE
271 ;;
272 stop)
273 echo -n "Shutting down rxstack "
274 ## Stop daemon with killproc(8) and if this fails
275 ## killproc sets the return value according to LSB.
276 ## Usage on RH: killproc [-p pidfile] [-d delay] {progrm} [-signal]
277
278 ## This one signal TERM followed by e.g. signal KILL
279 killproc $RXSTACK_BIN
280 ## or only with signal TERM
281 # killproc $RXSTACK_BIN -TERM
282
283 ## Remember status and be verbose
284 rc_status -v
285
286 ## Remove PIDFILE it not automatically renmoved
287 if test -e $RXSTACK_PIDFILE ; then
288 rm -f $RXSTACK_PIDFILE
289 fi
290 ;;
291 try-restart|condrestart)
292 ## Do a restart only if the service was active before.
293 ## Note: try-restart is now part of LSB (as of 1.9).
294 ## RH has a similar command named condrestart.
295 if test "$1" = "condrestart"; then
296 echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
297 fi
298 $0 status
299 if test $? = 0; then
300 $0 restart
301 else
302 rc_reset # Not running is not a failure.
303 fi
304 ## Remember status and be quiet
305 rc_status
306 ;;
307 restart)
308 ## Stop the service and regardless of whether it was
309 ## running or not, start it again.
310 $0 stop
311 $0 start
312
313 ## Remember status and be quiet
314 rc_status
315 ;;
316 force-reload)
317 ## Signal the daemon to reload its config. Most daemons
318 ## do this on signal 1 (SIGHUP).
319 ## If it does not support it, restart the service if it
320 ## is running.
321
322 echo -n "Reload service rxstack "
323 ## if it supports it:
324 killproc -HUP $RXSTACK_BIN
325 #touch /var/run/rxstack.pid
326 rc_status -v
327
328 ## Otherwise:
329 #$0 try-restart
330 #rc_status
331 ;;
332 reload)
333 ## Like force-reload, but if daemon does not support
334 ## signaling, do nothing (!)
335
336 ## If it supports signaling:
337 echo -n "Reload service rxstack "
338 killproc -HUP $RXSTACK_BIN
339 #touch /var/run/rxstack.pid
340 rc_status -v
341
342 ## Otherwise if it does not support reload:
343 #rc_failed 3
344 #rc_status -v
345 ;;
346 status)
347 echo -n "Checking for service rxstack "
348 ## Check status with checkproc(8), if process is running
349 ## checkproc will return with exit status 0.
350
351 ## Return value is slightly different for the status command:
352 ## 0 - service up and running
353 ## 1 - service dead, but /var/run/ pid file exists
354 ## 2 - service dead, but /var/lock/ lock file exists
355 ## 3 - service not running (unused)
356 ## 4 - service status unknown :-(
357 ## 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
358
359 ## NOTE: checkproc returns LSB compliant status values.
360 checkproc $RXSTACK_BIN
361 ## NOTE: rc_status knows that we called this init script with
362 ## "status" option and adapts its messages accordingly.
363 rc_status -v
364 ;;
365 probe)
366 ## Optional: Probe for the necessity of a reload, print out the
367 ## argument to this init script which is required for a reload.
368 ## Note: probe is not (yet) part of LSB (as of 1.9)
369
370 test /etc/rxstack/rxstack.conf -nt /var/run/rxstack.pid && echo reload
371 ;;
372 *)
373 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
374 exit 1
375 ;;
376 esac
377 rc_exit