Logoj0ke.net Open Build Service > Projects > server:monitoring:branches:gearman:1.0.1 > icinga-mod_gearman > mod_gearman-worker-suse.init
Sign Up | Log In

File mod_gearman-worker-suse.init of Package icinga-mod_gearman

x
 
1
#!/bin/sh
2
#
3
#     Copyright (C) 2011 Carsten Schoene, Linux Administrator Networks 
4
#          
5
#     This library is free software; you can redistribute it and/or modify it
6
#     under the terms of the GNU Lesser General Public License as published by
7
#     the Free Software Foundation; either version 2.1 of the License, or (at
8
#     your option) any later version.
9
#                 
10
#     This library is distributed in the hope that it will be useful, but
11
#     WITHOUT ANY WARRANTY; without even the implied warranty of
12
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
#     Lesser General Public License for more details.
14
#      
15
#     You should have received a copy of the GNU Lesser General Public
16
#     License along with this library; if not, write to the Free Software
17
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
18
#     USA.
19
#
20
# /etc/init.d/mod_gearman_worker
21
#   and its symbolic link
22
# /(usr/)sbin/rcmod_gearman_worker
23
#
24
#
25
### BEGIN INIT INFO
26
# Provides:          mod_gearman_worker
27
# Required-Start:    $syslog $remote_fs
28
# Should-Start:      $time
29
# Required-Stop:     $syslog $remote_fs
30
# Should-Stop:       $null
31
# Default-Start:     3 5
32
# Default-Stop:      0 1 2 6
33
# Short-Description: mod_gearman_worker daemon
34
# Description:       Start mod_gearman_worker
35
### END INIT INFO
36
# 
37
38
# Check for missing binaries (stale symlinks should not happen)
39
# Note: Special treatment of stop for LSB conformance
40
mod_gearman_worker_BIN=/usr/bin/mod_gearman_worker
41
MOD_GM_PIDFILE=/var/run/mod_gearman/mod_gearman_worker.pid
42
MOD_GM_CONFIG=/etc/mod_gearman/mod_gearman_worker.conf
43
test -x $mod_gearman_worker_BIN || { echo "$mod_gearman_worker_BIN not installed"; 
44
    if [ "$1" = "stop" ]; then exit 0;
45
    else exit 5; fi; }
46
47
# Check for existence of needed config file and read it
48
mod_gearman_worker_MOD_GM_CONFIG=/etc/sysconfig/mod_gearman_worker
49
test -r $mod_gearman_worker_MOD_GM_CONFIG || { echo "$mod_gearman_worker_MOD_GM_CONFIG not existing";
50
    if [ "$1" = "stop" ]; then exit 0;
51
    else exit 6; fi; }
52
53
# Read config   
54
. $mod_gearman_worker_MOD_GM_CONFIG
55
56
# Source LSB init functions
57
# providing start_daemon, killproc, pidofproc, 
58
# log_success_msg, log_failure_msg and log_warning_msg.
59
# This is currently not used by UnitedLinux based distributions and
60
# not needed for init scripts for UnitedLinux only. If it is used,
61
# the functions from rc.status should not be sourced or used.
62
#. /lib/lsb/init-functions
63
64
# Shell functions sourced from /etc/rc.status:
65
#      rc_check         check and set local and overall rc status
66
#      rc_status        check and set local and overall rc status
67
#      rc_status -v     be verbose in local rc status and clear it afterwards
68
#      rc_status -v -r  ditto and clear both the local and overall rc status
69
#      rc_status -s     display "skipped" and exit with status 3
70
#      rc_status -u     display "unused" and exit with status 3
71
#      rc_failed        set local and overall rc status to failed
72
#      rc_failed <num>  set local and overall rc status to <num>
73
#      rc_reset         clear both the local and overall rc status
74
#      rc_exit          exit appropriate to overall rc status
75
#      rc_active        checks whether a service is activated by symlinks
76
. /etc/rc.status
77
78
# Reset status of this service
79
rc_reset
80
81
# Return values acc. to LSB for all commands but status:
82
# 0   - success
83
# 1       - generic or unspecified error
84
# 2       - invalid or excess argument(s)
85
# 3       - unimplemented feature (e.g. "reload")
86
# 4       - user had insufficient privileges
87
# 5       - program is not installed
88
# 6       - program is not configured
89
# 7       - program is not running
90
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
91
# 
92
# Note that starting an already running service, stopping
93
# or restarting a not-running service as well as the restart
94
# with force-reload (in case signaling is not supported) are
95
# considered a success.
96
97
case "$1" in
98
    start)
99
    echo -n "Starting mod_gearman_worker "
100
    ## Start daemon with startproc(8). If this fails
101
    ## the return value is set appropriately by startproc.
102
    /sbin/startproc -u ${MOD_GM_USERID} $mod_gearman_worker_BIN -d --config=${MOD_GM_CONFIG} --pidfile=${MOD_GM_PIDFILE}
103
104
    # Remember status and be verbose
105
    rc_status -v
106
    ;;
107
    stop)
108
    echo -n "Shutting down mod_gearman_worker "
109
    ## Stop daemon with killproc(8) and if this fails
110
    ## killproc sets the return value according to LSB.
111
112
    /sbin/killproc $mod_gearman_worker_BIN -p ${MOD_GM_PIDFILE}
113
114
    # Remember status and be verbose
115
    rc_status -v
116
    ;;
117
    try-restart|condrestart)
118
    ## Do a restart only if the service was active before.
119
    ## Note: try-restart is now part of LSB (as of 1.9).
120
    ## RH has a similar command named condrestart.
121
    if test "$1" = "condrestart"; then
122
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
123
    fi
124
    $0 status
125
    if test $? = 0; then
126
        $0 restart
127
    else
128
        rc_reset    # Not running is not a failure.
129
    fi
130
    # Remember status and be quiet
131
    rc_status
132
    ;;
133
    restart)
134
    ## Stop the service and regardless of whether it was
135
    ## running or not, start it again.
136
    $0 stop
137
    $0 start
138
139
    # Remember status and be quiet
140
    rc_status
141
    ;;
142
    force-reload)
143
    ## Signal the daemon to reload its config. Most daemons
144
    ## do this on signal 1 (SIGHUP).
145
    ## If it does not support it, restart the service if it
146
    ## is running.
147
148
    echo -n "Reload service mod_gearman_worker "
149
    ## if it supports it:
150
    /sbin/killproc -HUP $mod_gearman_worker_BIN
151
    #touch /var/run/mod_gearman_worker.pid
152
    rc_status -v
153
154
    ## Otherwise:
155
    #$0 try-restart
156
    #rc_status
157
    ;;
158
    reload)
159
    ## Like force-reload, but if daemon does not support
160
    ## signaling, do nothing (!)
161
162
    # If it supports signaling:
163
    echo -n "Reload service mod_gearman_worker "
164
    /sbin/killproc -HUP $mod_gearman_worker_BIN
165
    #touch /var/run/mod_gearman_worker.pid
166
    rc_status -v
167
    
168
    ## Otherwise if it does not support reload:
169
    #rc_failed 3
170
    #rc_status -v
171
    ;;
172
    status)
173
    echo -n "Checking for service mod_gearman_worker "
174
    ## Check status with checkproc(8), if process is running
175
    ## checkproc will return with exit status 0.
176
177
    # Return value is slightly different for the status command:
178
    # 0 - service up and running
179
    # 1 - service dead, but /var/run/  pid  file exists
180
    # 2 - service dead, but /var/lock/ lock file exists
181
    # 3 - service not running (unused)
182
    # 4 - service status unknown :-(
183
    # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
184
    
185
    # NOTE: checkproc returns LSB compliant status values.
186
    /sbin/checkproc $mod_gearman_worker_BIN
187
    # NOTE: rc_status knows that we called this init script with
188
    # "status" option and adapts its messages accordingly.
189
    rc_status -v
190
    ;;
191
    probe)
192
    ## Optional: Probe for the necessity of a reload, print out the
193
    ## argument to this init script which is required for a reload.
194
    ## Note: probe is not (yet) part of LSB (as of 1.9)
195
196
    test /etc/mod_gearman/mod_gearman_worker.conf -nt ${MOD_GM_PIDFILE} && echo reload
197
    ;;
198
    *)
199
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
200
    exit 1
201
    ;;
202
esac
203
rc_exit
204