3 # LSB system startup script for service/daemon p910nd
4 # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
5 # Copyright (C) 2008 Ken Yap
7 # This library is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or (at
10 # your option) any later version.
12 # This library is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
23 # and its symbolic link
24 # /(usr/)sbin/rcp910nd
26 # Template system startup script for some example service/daemon p910nd
28 # LSB compatible service control script; see http://www.linuxbase.org/spec/
30 # Note: This template uses functions rc_XXX defined in /etc/rc.status on
31 # UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your
32 # script on this template and ensure that it works on non UL based LSB
33 # compliant Linux distributions, you either have to provide the rc.status
34 # functions from UL or change the script to work without them.
35 # See skeleton.compat for a template that works with other distros as well.
38 # description: p910nd daemon providing network printer access
42 # Required-Start: $syslog
44 # Required-Stop: $syslog
47 # Default-Stop: 0 1 2 6
48 # Short-Description: p910nd daemon providing network printer access
49 # Description: Start p910nd to provide port 9100+n printer service
52 # Any extensions to the keywords given above should be preceeded by
53 # X-VendorTag- according to LSB.
55 # Notes on Required-Start/Should-Start:
56 # * There are two different issues that are solved by Required-Start
58 # (a) Hard dependencies: This is used by the runlevel editor to determine
59 # which services absolutely need to be started to make the start of
60 # this service make sense. Example: nfsserver should have
61 # Required-Start: $portmap
62 # Also, required services are started before the dependent ones.
63 # The runlevel editor will warn about such missing hard dependencies
64 # and suggest enabling. During system startup, you may expect an error,
65 # if the dependency is not fulfilled.
66 # (b) Specifying the init script ordering, not real (hard) dependencies.
67 # This is needed by insserv to determine which service should be
68 # started first (and at a later stage what services can be started
69 # in parallel). The tag Should-Start: is used for this.
70 # It tells, that if a service is available, it should be started
71 # before. If not, never mind.
72 # * When specifying hard dependencies or ordering requirements, you can
73 # use names of services (contents of their Provides: section)
74 # or pseudo names starting with a $. The following ones are available
75 # according to LSB (1.1):
76 # $local_fs all local file systems are mounted
77 # (most services should need this!)
78 # $remote_fs all remote file systems are mounted
79 # (note that /usr may be remote, so
80 # many services should Require this!)
81 # $syslog system logging facility up
82 # $network low level networking (eth card, ...)
83 # $named hostname resolution available
84 # $netdaemons all network daemons are running
85 # The $netdaemons pseudo service has been removed in LSB 1.2.
86 # For now, we still offer it for backward compatibility.
87 # These are new (LSB 1.2):
88 # $time the system time has been set correctly
89 # $portmap SunRPC portmapping service available
90 # UnitedLinux/SUSE/Novell extensions:
91 # $ALL indicates that a script should be inserted
93 # * The services specified in the stop tags
94 # (Required-Stop/Should-Stop)
95 # specify which services need to be still running when this service
96 # is shut down. Often the entries there are just copies or a subset
97 # from the respective start tag.
98 # * Should-Start/Stop are now part of LSB as of 2.0,
99 # formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
100 # insserv does support both variants.
101 # * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
102 # (%fillup_and_insserv macro in %post of many RPMs) to specify whether
103 # a startup script should default to be enabled after installation.
106 # 0 - halt/poweroff 6 - reboot
107 # 1 - single user 2 - multiuser without network exported
108 # 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm)
110 # Note on script names:
111 # http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
112 # A registry has been set up to manage the init script namespace.
113 # http://www.lanana.org/
114 # Please use the names already registered or register one or use a
118 # Check for missing binaries (stale symlinks should not happen)
119 # Note: Special treatment of stop for LSB conformance
120 P910ND_BIN
=/usr
/sbin
/p910nd
121 test -x $P910ND_BIN ||
{ echo "$P910ND_BIN not installed";
122 if [ "$1" = "stop" ]; then exit 0;
125 # Check for existence of needed config file and read it
126 P910ND_CONFIG
=/etc
/sysconfig
/p910nd
127 test -r $P910ND_CONFIG ||
{ echo "$P910ND_CONFIG not found";
128 if [ "$1" = "stop" ]; then exit 0;
134 # Source LSB init functions
135 # providing start_daemon, killproc, pidofproc,
136 # log_success_msg, log_failure_msg and log_warning_msg.
137 # This is currently not used by UnitedLinux based distributions and
138 # not needed for init scripts for UnitedLinux only. If it is used,
139 # the functions from rc.status should not be sourced or used.
140 #. /lib/lsb/init-functions
142 # Shell functions sourced from /etc/rc.status:
143 # rc_check check and set local and overall rc status
144 # rc_status check and set local and overall rc status
145 # rc_status -v be verbose in local rc status and clear it afterwards
146 # rc_status -v -r ditto and clear both the local and overall rc status
147 # rc_status -s display "skipped" and exit with status 3
148 # rc_status -u display "unused" and exit with status 3
149 # rc_failed set local and overall rc status to failed
150 # rc_failed <num> set local and overall rc status to <num>
151 # rc_reset clear both the local and overall rc status
152 # rc_exit exit appropriate to overall rc status
153 # rc_active checks whether a service is activated by symlinks
155 # Use the SUSE rc_ init script functions;
156 # emulate them on LSB, RH and other systems
158 # Default: Assume sysvinit binaries exist
159 start_daemon
() { /sbin
/start_daemon
${1+"$@"}; }
160 killproc
() { /sbin
/killproc
${1+"$@"}; }
161 pidofproc
() { /sbin
/pidofproc
${1+"$@"}; }
162 checkproc
() { /sbin
/checkproc
${1+"$@"}; }
163 if test -e /etc
/rc.status
; then
164 # SUSE rc script library
170 if test "${_cmd}" = "status"; then
171 _SMSG
=(running dead dead unused unknown reserved
)
174 _SMSG
=(done failed failed missed failed skipped unused failed failed reserved
)
177 if test -e /lib
/lsb
/init-functions
; then
179 .
/lib
/lsb
/init-functions
182 if test ${_RC_RV} = 0; then
183 log_success_msg
" [${_SMSG[${_RC_RV}]}] "
185 log_failure_msg
" [${_SMSG[${_RC_RV}]}] "
188 # TODO: Add checking for lockfiles
189 checkproc
() { return pidofproc
${1+"$@"} >/dev
/null
2>&1; }
190 elif test -e /etc
/init.d
/functions
; then
192 .
/etc
/init.d
/functions
195 #echo -n " [${_SMSG[${_RC_RV}]}] "
196 if test ${_RC_RV} = 0; then
197 success
" [${_SMSG[${_RC_RV}]}] "
199 failure
" [${_SMSG[${_RC_RV}]}] "
202 checkproc
() { return status
${1+"$@"}; }
203 start_daemon
() { return daemon
${1+"$@"}; }
206 echo_rc
() { echo " [${_SMSG[${_RC_RV}]}] "; }
208 rc_reset
() { _RC_RV
=0; }
211 if test -z "$1"; then
213 elif test "$1" != "0"; then
225 if test "$1" = "-r"; then _RC_RV
=0; shift; fi
226 if test "$1" = "-s"; then rc_failed
5; echo_rc
; rc_failed
3; shift; fi
227 if test "$1" = "-u"; then rc_failed
${_RC_UNUSED}; echo_rc
; rc_failed
3; shift; fi
228 if test "$1" = "-v"; then echo_rc
; shift; fi
229 if test "$1" = "-r"; then _RC_RV
=0; shift; fi
232 rc_exit
() { exit ${_RC_RV}; }
235 if test -z "$RUNLEVEL"; then read RUNLEVEL REST
< <(/sbin
/runlevel
); fi
236 if test -e /etc
/init.d
/S
[0-9][0-9]${1}; then return 0; fi
241 # Reset status of this service
244 # Return values acc. to LSB for all commands but status:
246 # 1 - generic or unspecified error
247 # 2 - invalid or excess argument(s)
248 # 3 - unimplemented feature (e.g. "reload")
249 # 4 - user had insufficient privileges
250 # 5 - program is not installed
251 # 6 - program is not configured
252 # 7 - program is not running
253 # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
255 # Note that starting an already running service, stopping
256 # or restarting a not-running service as well as the restart
257 # with force-reload (in case signaling is not supported) are
258 # considered a success.
262 echo -n "Starting p910nd "
263 ## Start daemon with startproc(8). If this fails
264 ## the return value is set appropriately by startproc.
265 startproc
$P910ND_BIN $P910ND_OPTS $P910ND_NUM
267 # Remember status and be verbose
271 echo -n "Shutting down p910nd "
272 ## Stop daemon with killproc(8) and if this fails
273 ## killproc sets the return value according to LSB.
275 killproc
-TERM $P910ND_BIN
277 # Remember status and be verbose
280 try-restart|condrestart
)
281 ## Do a restart only if the service was active before.
282 ## Note: try-restart is now part of LSB (as of 1.9).
283 ## RH has a similar command named condrestart.
284 if test "$1" = "condrestart"; then
285 echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
291 rc_reset
# Not running is not a failure.
293 # Remember status and be quiet
297 ## Stop the service and regardless of whether it was
298 ## running or not, start it again.
302 # Remember status and be quiet
306 ## Signal the daemon to reload its config. Most daemons
307 ## do this on signal 1 (SIGHUP).
308 ## If it does not support it, restart the service if it
311 echo -n "Reload service p910nd "
312 ## if it supports it:
313 #killproc -HUP $P910ND_BIN
314 #touch /var/run/p910nd.pid
322 ## Like force-reload, but if daemon does not support
323 ## signaling, do nothing (!)
325 # If it supports signaling:
326 echo -n "Reload service p910nd "
327 #killproc -HUP $P910ND_BIN
328 #touch /var/run/p910nd.pid
331 ## Otherwise if it does not support reload:
336 echo -n "Checking for service p910nd "
337 ## Check status with checkproc(8), if process is running
338 ## checkproc will return with exit status 0.
340 # Return value is slightly different for the status command:
341 # 0 - service up and running
342 # 1 - service dead, but /var/run/ pid file exists
343 # 2 - service dead, but /var/lock/ lock file exists
344 # 3 - service not running (unused)
345 # 4 - service status unknown :-(
346 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
348 # NOTE: checkproc returns LSB compliant status values.
349 checkproc
$P910ND_BIN
350 # NOTE: rc_status knows that we called this init script with
351 # "status" option and adapts its messages accordingly.
355 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"