~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to resources/OCF/ClusterMon

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2010-02-17 21:59:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217215918-06paxph5do4saw8v
Tags: 3.0.2-0ubuntu1
* New upstream release
* Drop hard dep on pacemaker for heartbet; moved to Recommends
* debian/heartbeat.install:
  - follow upstream changes
* debian/control:
  - added docbook-xsl and xsltproc to build depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
#
4
 
#       ClusterMon OCF RA. Does nothing but wait a few seconds, can be
5
 
#       configured to fail occassionally.
6
 
#
7
 
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Br�e
8
 
#                    All Rights Reserved.
9
 
#
10
 
# This program is free software; you can redistribute it and/or modify
11
 
# it under the terms of version 2 of the GNU General Public License as
12
 
# published by the Free Software Foundation.
13
 
#
14
 
# This program is distributed in the hope that it would be useful, but
15
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
#
18
 
# Further, this software is distributed without any warranty that it is
19
 
# free of the rightful claim of any third person regarding infringement
20
 
# or the like.  Any license provided herein, whether implied or
21
 
# otherwise, applies only to this software file.  Patent licenses, if
22
 
# any, provided herein do not apply to combinations of this program with
23
 
# other software, or any other product whatsoever.
24
 
#
25
 
# You should have received a copy of the GNU General Public License
26
 
# along with this program; if not, write the Free Software Foundation,
27
 
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
 
#
29
 
# OCF instance parameters:
30
 
#       OCF_RESKEY_user
31
 
#       OCF_RESKEY_pidfile
32
 
#       OCF_RESKEY_update
33
 
#       OCF_RESKEY_extra_options
34
 
#       OCF_RESKEY_htmlfile
35
 
 
36
 
#######################################################################
37
 
# Initialization:
38
 
 
39
 
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
40
 
 
41
 
#######################################################################
42
 
 
43
 
meta_data() {
44
 
        cat <<END
45
 
<?xml version="1.0"?>
46
 
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
47
 
<resource-agent name="ClusterMon">
48
 
<version>1.0</version>
49
 
 
50
 
<longdesc lang="en">
51
 
This is a ClusterMon Resource Agent.
52
 
It outputs current cluster status to the html.
53
 
</longdesc>
54
 
<shortdesc lang="en">ClusterMon resource agent</shortdesc>
55
 
 
56
 
<parameters>
57
 
 
58
 
<parameter name="user" unique="0">
59
 
<longdesc lang="en">
60
 
The user we want to run crm_mon as
61
 
</longdesc>
62
 
<shortdesc lang="en">The user we want to run crm_mon as</shortdesc>
63
 
<content type="string" default="root" />
64
 
</parameter>
65
 
 
66
 
<parameter name="update" unique="0">
67
 
<longdesc lang="en">
68
 
How frequently should we update the cluster status
69
 
</longdesc>
70
 
<shortdesc lang="en">Update interval</shortdesc>
71
 
<content type="integer" default="15" />
72
 
</parameter>
73
 
 
74
 
<parameter name="extra_options" unique="0">
75
 
<longdesc lang="en">
76
 
Additional options to pass to crm_mon.  Eg. -n -r
77
 
</longdesc>
78
 
<shortdesc lang="en">Extra options</shortdesc>
79
 
<content type="string" default="" />
80
 
</parameter>
81
 
 
82
 
<parameter name="pidfile" unique="1">
83
 
<longdesc lang="en">
84
 
PID file location to ensure only one instance is running
85
 
</longdesc>
86
 
<shortdesc lang="en">PID file</shortdesc>
87
 
<content type="string" default="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.pid" />
88
 
</parameter>
89
 
 
90
 
<parameter name="htmlfile" unique="1" required="1">
91
 
<longdesc lang="en">
92
 
Location to write HTML output to.
93
 
</longdesc>
94
 
<shortdesc lang="en">HTML output</shortdesc>
95
 
<content type="string" default="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.html" />
96
 
</parameter>
97
 
</parameters>
98
 
 
99
 
<actions>
100
 
<action name="start"   timeout="90" />
101
 
<action name="stop"    timeout="100" />
102
 
<action name="monitor" depth="0"  timeout="20" interval="10" start-delay="0" />
103
 
<action name="meta-data"  timeout="5" />
104
 
<action name="validate-all"  timeout="30" />
105
 
</actions>
106
 
</resource-agent>
107
 
END
108
 
}
109
 
 
110
 
#######################################################################
111
 
 
112
 
ClusterMon_usage() {
113
 
        cat <<END
114
 
usage: $0 {start|stop|monitor|validate-all|meta-data}
115
 
 
116
 
Expects to have a fully populated OCF RA-compliant environment set.
117
 
END
118
 
}
119
 
 
120
 
ClusterMon_exit() {
121
 
        if [ $1 != 0 ]; then
122
 
                exit $OCF_ERR_GENERIC
123
 
        else
124
 
                exit $OCF_SUCCESS
125
 
        fi
126
 
}
127
 
 
128
 
ClusterMon_start() {
129
 
    cmd_prefix=""
130
 
    cmd_suffix=""
131
 
    if [ ! -z $OCF_RESKEY_user ]; then
132
 
        su - $OCF_RESKEY_user -c "${HA_SBIN_DIR}/crm_mon -p $OCF_RESKEY_pidfile -d -i $OCF_RESKEY_update $OCF_RESKEY_extra_options -h $OCF_RESKEY_htmlfile"
133
 
    else
134
 
        ${HA_SBIN_DIR}/crm_mon -p $OCF_RESKEY_pidfile -d -i $OCF_RESKEY_update $OCF_RESKEY_extra_options -h $OCF_RESKEY_htmlfile
135
 
    fi
136
 
    ClusterMon_exit $?
137
 
}
138
 
 
139
 
ClusterMon_stop() {
140
 
    if [ -f $OCF_RESKEY_pidfile ]; then
141
 
        pid=`cat $OCF_RESKEY_pidfile`
142
 
    fi
143
 
    if [ ! -z $pid ]; then
144
 
        kill -9 $pid
145
 
        rc=$?
146
 
        if [ $rc = 0 ]; then
147
 
            rm $OCF_RESKEY_pidfile
148
 
        fi
149
 
        ClusterMon_exit $rc
150
 
    fi
151
 
    ClusterMon_exit 0
152
 
}
153
 
 
154
 
ClusterMon_monitor() {
155
 
    if [ -f $OCF_RESKEY_pidfile ]; then
156
 
        pid=`cat $OCF_RESKEY_pidfile`
157
 
    fi
158
 
    if [ ! -z $pid ]; then
159
 
        kill -0 $pid
160
 
        if [ $? = 0 ]; then
161
 
            exit $OCF_SUCCESS
162
 
        fi
163
 
    fi
164
 
    exit $OCF_NOT_RUNNING
165
 
}
166
 
 
167
 
CheckOptions() {
168
 
while getopts Vi:nrh:cdp: OPTION
169
 
do
170
 
    case $OPTION in
171
 
    V|n|r|c|d);;
172
 
    i)  ocf_log warn "You should not have specified the -i option, since OCF_RESKEY_update is set already!";;
173
 
    h)  ocf_log warn "You should not have specified the -h option, since OCF_RESKEY_htmlfile is set already!";;
174
 
    p)  ocf_log warn "You should not have specified the -p option, since OCF_RESKEY_pidfile is set already!";;
175
 
    *)  return $OCF_ERR_ARGS;;
176
 
    esac
177
 
done            
178
 
 
179
 
if [ $? -ne 0 ]; then
180
 
    return $OCF_ERR_ARGS
181
 
fi
182
 
 
183
 
# We should have eaten all options at this stage
184
 
shift $(($OPTIND -1))
185
 
if [ $# -gt 0 ]; then
186
 
    false
187
 
else
188
 
    true
189
 
fi
190
 
}
191
 
 
192
 
ClusterMon_validate() {
193
 
# Existence of the user
194
 
    if [ ! -z $OCF_RESKEY_user ]; then
195
 
        getent passwd "$OCF_RESKEY_user" >/dev/null
196
 
        if [ $? -eq 0 ]; then
197
 
            : Yes, user exists. We can further check his permission on crm_mon if necessary
198
 
        else
199
 
            ocf_log err "The user $OCF_RESKEY_user does not exist!"
200
 
            exit $OCF_ERR_ARGS
201
 
        fi
202
 
    fi
203
 
 
204
 
# Pidfile better be an absolute path
205
 
    case $OCF_RESKEY_pidfile in
206
 
        /*) ;;
207
 
        *) ocf_log warn "You should have pidfile($OCF_RESKEY_pidfile) of absolute path!" ;;
208
 
    esac
209
 
 
210
 
# Check the update interval
211
 
    if ocf_is_decimal "$OCF_RESKEY_update" && [ $OCF_RESKEY_update -gt 0 ]; then
212
 
        :
213
 
    else
214
 
        ocf_log err "Invalid update interval $OCF_RESKEY_update. It should be positive integer!"
215
 
        exit $OCF_ERR_ARGS
216
 
    fi
217
 
 
218
 
    if CheckOptions $OCF_RESKEY_extra_options; then
219
 
        :
220
 
    else
221
 
        ocf_log err "Invalid options $OCF_RESKEY_extra_options!"
222
 
        exit $OCF_ERR_ARGS
223
 
    fi
224
 
 
225
 
# Htmlfile better be an absolute path
226
 
    case $OCF_RESKEY_htmlfile in
227
 
        /*) ;;
228
 
        *) ocf_log warn "You should have htmlfile($OCF_RESKEY_htmlfile) of absolute path!" ;;
229
 
    esac
230
 
 
231
 
     
232
 
    echo "Validate OK"
233
 
    return $OCF_SUCCESS
234
 
}
235
 
 
236
 
if [ $# -ne 1 ]; then
237
 
    ClusterMon_usage
238
 
    exit $OCF_ERR_ARGS
239
 
fi
240
 
 
241
 
: ${OCF_RESKEY_update:="15000"}
242
 
: ${OCF_RESKEY_pidfile:="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.pid"}
243
 
: ${OCF_RESKEY_htmlfile:="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.html"}
244
 
 
245
 
OCF_RESKEY_update=`expr $OCF_RESKEY_update / 1000`
246
 
 
247
 
case $__OCF_ACTION in
248
 
meta-data)      meta_data
249
 
                exit $OCF_SUCCESS
250
 
                ;;
251
 
start)          ClusterMon_start
252
 
                ;;
253
 
stop)           ClusterMon_stop
254
 
                ;;
255
 
monitor)        ClusterMon_monitor
256
 
                ;;
257
 
validate-all)   ClusterMon_validate
258
 
                ;;
259
 
usage|help)     ClusterMon_usage
260
 
                exit $OCF_SUCCESS
261
 
                ;;
262
 
*)              ClusterMon_usage
263
 
                exit $OCF_ERR_UNIMPLEMENTED
264
 
                ;;
265
 
esac
266
 
 
267
 
exit $?