Logoj0ke.net Open Build Service > Projects > server:monitoring:branches:gearman:1.0.1 > gearman > gearmand.init
Sign Up | Log In

File gearmand.init of Package gearman

x
 
1
#!/bin/sh
2
#
3
#     Template SUSE system startup script for example service/daemon gearmand
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
19
#     USA.
20
#
21
# /etc/init.d/gearmand
22
#   and its symbolic link
23
# /(usr/)sbin/rcgearmand
24
#
25
# Template system startup script for some example service/daemon gearmand
26
#
27
# LSB compatible service control script; see http://www.linuxbase.org/spec/
28
#
29
# Note: This template uses functions rc_XXX defined in /etc/rc.status on
30
# UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your
31
# script on this template and ensure that it works on non UL based LSB
32
# compliant Linux distributions, you either have to provide the rc.status
33
# functions from UL or change the script to work without them.
34
# See skeleton.compat for a template that works with other distros as well.
35
#
36
### BEGIN INIT INFO
37
# Provides:          gearmand
38
# Required-Start:    $syslog $remote_fs
39
# Should-Start:      $time ypbind smtp
40
# Required-Stop:     $syslog $remote_fs
41
# Should-Stop:       ypbind smtp
42
# Default-Start:     3 5
43
# Default-Stop:      0 1 2 6
44
# Short-Description: gearman deamon
45
# Description:       Start gearmand to allow XY and provide YZ
46
#   continued on second line by '#<TAB>'
47
#   should contain enough info for the runlevel editor
48
#   to give admin some idea what this service does and
49
#   what it's needed for ...
50
#   (The Short-Description should already be a good hint.)
51
### END INIT INFO
52
#
53
# Any extensions to the keywords given above should be preceeded by
54
# X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB.
55
#
56
# Notes on Required-Start/Should-Start:
57
# * There are two different issues that are solved by Required-Start
58
#    and Should-Start
59
# (a) Hard dependencies: This is used by the runlevel editor to determine
60
#     which services absolutely need to be started to make the start of
61
#     this service make sense. Example: nfsserver should have
62
#     Required-Start: $portmap
63
#     Also, required services are started before the dependent ones.
64
#     The runlevel editor will warn about such missing hard dependencies
65
#     and suggest enabling. During system startup, you may expect an error,
66
#     if the dependency is not fulfilled.
67
# (b) Specifying the init script ordering, not real (hard) dependencies.
68
#     This is needed by insserv to determine which service should be
69
#     started first (and at a later stage what services can be started
70
#     in parallel). The tag Should-Start: is used for this.
71
#     It tells, that if a service is available, it should be started
72
#     before. If not, never mind.
73
# * When specifying hard dependencies or ordering requirements, you can
74
#   use names of services (contents of their Provides: section)
75
#   or pseudo names starting with a $. The following ones are available
76
#   according to LSB (1.1):
77
#   $local_fs       all local file systems are mounted
78
#               (most services should need this!)
79
#   $remote_fs      all remote file systems are mounted
80
#               (note that /usr may be remote, so
81
#                many services should Require this!)
82
#   $syslog         system logging facility up
83
#   $network        low level networking (eth card, ...)
84
#   $named          hostname resolution available
85
#   $netdaemons     all network daemons are running
86
#   The $netdaemons pseudo service has been removed in LSB 1.2.
87
#   For now, we still offer it for backward compatibility.
88
#   These are new (LSB 1.2):
89
#   $time           the system time has been set correctly
90
#   $portmap        SunRPC portmapping service available
91
#   UnitedLinux extensions:
92
#   $ALL            indicates that a script should be inserted
93
#               at the end
94
# * The services specified in the stop tags
95
#   (Required-Stop/Should-Stop)
96
#   specify which services need to be still running when this service
97
#   is shut down. Often the entries there are just copies or a subset
98
#   from the respective start tag.
99
# * Should-Start/Stop are now part of LSB as of 2.0,
100
#   formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
101
#   insserv does support both variants.
102
# * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
103
#   (%fillup_and_insserv macro in %post of many RPMs) to specify whether
104
#   a startup script should default to be enabled after installation.
105
#   It's not used by insserv.
106
#
107
# Note on runlevels:
108
# 0 - halt/poweroff             6 - reboot
109
# 1 - single user           2 - multiuser without network exported
110
# 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
111
#
112
# Note on script names:
113
# http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
114
# A registry has been set up to manage the init script namespace.
115
# http://www.lanana.org/
116
# Please use the names already registered or register one or use a
117
# vendor prefix.
118
119
120
# Check for missing binaries (stale symlinks should not happen)
121
# Note: Special treatment of stop for LSB conformance
122
GEARMAND_BIN=/usr/sbin/gearmand
123
test -x $GEARMAND_BIN || { echo "$GEARMAND_BIN not installed";
124
    if [ "$1" = "stop" ]; then exit 0;
125
    else exit 5; fi; }
126
127
# Check for existence of needed config file and read it
128
GEARMAND_CONFIG=/etc/sysconfig/gearmand
129
test -r $GEARMAND_CONFIG || { echo "$GEARMAND_CONFIG not existing";
130
    if [ "$1" = "stop" ]; then exit 0;
131
    else exit 6; fi; }
132
133
# Read config
134
. $GEARMAND_CONFIG
135
136
# Source LSB init functions
137
# providing start_daemon, killproc, pidofproc,
138
# log_success_msg, log_failure_msg and log_warning_msg.
139
# This is currently not used by UnitedLinux based distributions and
140
# not needed for init scripts for UnitedLinux only. If it is used,
141
# the functions from rc.status should not be sourced or used.
142
#. /lib/lsb/init-functions
143
144
# Shell functions sourced from /etc/rc.status:
145
#      rc_check         check and set local and overall rc status
146
#      rc_status        check and set local and overall rc status
147
#      rc_status -v     be verbose in local rc status and clear it afterwards
148
#      rc_status -v -r  ditto and clear both the local and overall rc status
149
#      rc_status -s     display "skipped" and exit with status 3
150
#      rc_status -u     display "unused" and exit with status 3
151
#      rc_failed        set local and overall rc status to failed
152
#      rc_failed <num>  set local and overall rc status to <num>
153
#      rc_reset         clear both the local and overall rc status
154
#      rc_exit          exit appropriate to overall rc status
155
#      rc_active        checks whether a service is activated by symlinks
156
. /etc/rc.status
157
158
# Reset status of this service
159
rc_reset
160
161
# Return values acc. to LSB for all commands but status:
162
# 0   - success
163
# 1       - generic or unspecified error
164
# 2       - invalid or excess argument(s)
165
# 3       - unimplemented feature (e.g. "reload")
166
# 4       - user had insufficient privileges
167
# 5       - program is not installed
168
# 6       - program is not configured
169
# 7       - program is not running
170
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
171
#
172
# Note that starting an already running service, stopping
173
# or restarting a not-running service as well as the restart
174
# with force-reload (in case signaling is not supported) are
175
# considered a success.
176
177
case "$1" in
178
    start)
179
    echo -n "Starting gearmand "
180
    ## Start daemon with startproc(8). If this fails
181
    ## the return value is set appropriately by startproc.
182
    /sbin/startproc -u $GEARMAND_USER -g $GEARMAND_GROUP $GEARMAND_BIN --listen=$GEARMAND_IPADDR --port=$GEARMAND_PORT -l $GEARMAND_LOG -P $GEARMAND_PID
183
184
    # Remember status and be verbose
185
    rc_status -v
186
    ;;
187
    stop)
188
    echo -n "Shutting down gearmand "
189
    ## Stop daemon with killproc(8) and if this fails
190
    ## killproc sets the return value according to LSB.
191
192
    /sbin/killproc -TERM $GEARMAND_BIN
193
194
    # Remember status and be verbose
195
    rc_status -v
196
    ;;
197
    try-restart|condrestart)
198
    ## Do a restart only if the service was active before.
199
    ## Note: try-restart is now part of LSB (as of 1.9).
200
    ## RH has a similar command named condrestart.
201
    if test "$1" = "condrestart"; then
202
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
203
    fi
204
    $0 status
205
    if test $? = 0; then
206
        $0 restart
207
    else
208
        rc_reset    # Not running is not a failure.
209
    fi
210
    # Remember status and be quiet
211
    rc_status
212
    ;;
213
    restart)
214
    ## Stop the service and regardless of whether it was
215
    ## running or not, start it again.
216
    $0 stop
217
    $0 start
218
219
    # Remember status and be quiet
220
    rc_status
221
    ;;
222
    force-reload)
223
    ## Signal the daemon to reload its config. Most daemons
224
    ## do this on signal 1 (SIGHUP).
225
    ## If it does not support it, restart the service if it
226
    ## is running.
227
228
    echo -n "Reload service gearmand "
229
    ## if it supports it:
230
    /sbin/killproc -HUP $GEARMAND_BIN
231
    #touch /var/run/FOO.pid
232
    rc_status -v
233
234
    ## Otherwise:
235
    #$0 try-restart
236
    #rc_status
237
    ;;
238
    reload)
239
    ## Like force-reload, but if daemon does not support
240
    ## signaling, do nothing (!)
241
242
    # If it supports signaling:
243
    echo -n "Reload service gearmand "
244
    /sbin/killproc -HUP $GEARMAND_BIN
245
    #touch /var/run/FOO.pid
246
    rc_status -v
247
248
    ## Otherwise if it does not support reload:
249
    #rc_failed 3
250
    #rc_status -v
251
    ;;
252
    status)
253
    echo -n "Checking for service gearmand "
254
    ## Check status with checkproc(8), if process is running
255
    ## checkproc will return with exit status 0.
256
257
    # Return value is slightly different for the status command:
258
    # 0 - service up and running
259
    # 1 - service dead, but /var/run/  pid  file exists
260
    # 2 - service dead, but /var/lock/ lock file exists
261
    # 3 - service not running (unused)
262
    # 4 - service status unknown :-(
263
    # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
264
265
    # NOTE: checkproc returns LSB compliant status values.
266
    /sbin/checkproc $GEARMAND_BIN
267
    # NOTE: rc_status knows that we called this init script with
268
    # "status" option and adapts its messages accordingly.
269
    rc_status -v
270
    ;;
271
    probe)
272
    ## Optional: Probe for the necessity of a reload, print out the
273
    ## argument to this init script which is required for a reload.
274
    ## Note: probe is not (yet) part of LSB (as of 1.9)
275
276
    test /etc/gearmand/gearmand.conf -nt /var/run/gearmand.pid && echo reload
277
    ;;
278
    *)
279
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
280
    exit 1
281
    ;;
282
esac
283
rc_exit
284