~ubuntu-branches/debian/stretch/resource-agents/stretch

« back to all changes in this revision

Viewing changes to heartbeat/pingd

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
ImportĀ upstreamĀ versionĀ 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#
 
4
#       pingd OCF Resource Agent
 
5
#       Records (in the CIB) the current number of ping nodes a
 
6
#          cluster node can connect to.
 
7
#
 
8
# Copyright (c) 2006 Andrew Beekhof
 
9
#                    All Rights Reserved.
 
10
#
 
11
# This program is free software; you can redistribute it and/or modify
 
12
# it under the terms of version 2 of the GNU General Public License as
 
13
# published by the Free Software Foundation.
 
14
#
 
15
# This program is distributed in the hope that it would be useful, but
 
16
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
#
 
19
# Further, this software is distributed without any warranty that it is
 
20
# free of the rightful claim of any third person regarding infringement
 
21
# or the like.  Any license provided herein, whether implied or
 
22
# otherwise, applies only to this software file.  Patent licenses, if
 
23
# any, provided herein do not apply to combinations of this program with
 
24
# other software, or any other product whatsoever.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program; if not, write the Free Software Foundation,
 
28
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 
29
#
 
30
#######################################################################
 
31
# Initialization:
 
32
 
 
33
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
34
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
35
 
 
36
#######################################################################
 
37
 
 
38
meta_data() {
 
39
        cat <<END
 
40
<?xml version="1.0"?>
 
41
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
42
<resource-agent name="pingd">
 
43
<version>1.0</version>
 
44
 
 
45
<longdesc lang="en">
 
46
Deprecation warning: This agent is deprecated and may be removed from
 
47
a future release. See the ocf:pacemaker:pingd resource agent for a
 
48
supported alternative. --
 
49
This is a pingd Resource Agent.
 
50
It records (in the CIB) the current number of ping nodes a node can connect to.
 
51
</longdesc>
 
52
<shortdesc lang="en">Monitors connectivity to specific hosts or
 
53
IP addresses ("ping nodes") (deprecated)</shortdesc>
 
54
 
 
55
<parameters>
 
56
 
 
57
<parameter name="pidfile" unique="0">
 
58
<longdesc lang="en">PID file</longdesc>
 
59
<shortdesc lang="en">PID file</shortdesc>
 
60
<content type="string" default="$HA_RSCTMP/pingd-${OCF_RESOURCE_INSTANCE}" />
 
61
</parameter>
 
62
 
 
63
 
 
64
<parameter name="user" unique="0">
 
65
<longdesc lang="en">
 
66
The user we want to run pingd as
 
67
</longdesc>
 
68
<shortdesc lang="en">The user we want to run pingd as</shortdesc>
 
69
<content type="string" default="root" />
 
70
</parameter>
 
71
 
 
72
<parameter name="dampen" unique="0">
 
73
<longdesc lang="en">
 
74
The time to wait (dampening) further changes occur
 
75
</longdesc>
 
76
<shortdesc lang="en">Dampening interval</shortdesc>
 
77
<content type="integer" default="1s"/>
 
78
</parameter>
 
79
 
 
80
<parameter name="set" unique="0">
 
81
<longdesc lang="en">
 
82
The name of the instance_attributes set to place the value in.  Rarely needs to be specified.
 
83
</longdesc>
 
84
<shortdesc lang="en">Set name</shortdesc>
 
85
<content type="integer" default=""/>
 
86
</parameter>
 
87
 
 
88
<parameter name="name" unique="0">
 
89
<longdesc lang="en">
 
90
The name of the attributes to set.  This is the name to be used in the constraints.
 
91
</longdesc>
 
92
<shortdesc lang="en">Attribute name</shortdesc>
 
93
<content type="integer" default="${OCF_RESOURCE_INSTANCE}"/>
 
94
</parameter>
 
95
 
 
96
<parameter name="section" unique="0">
 
97
<longdesc lang="en">
 
98
The section place the value in.  Rarely needs to be specified.
 
99
</longdesc>
 
100
<shortdesc lang="en">Section name</shortdesc>
 
101
<content type="integer" default=""/>
 
102
</parameter>
 
103
 
 
104
<parameter name="multiplier" unique="0">
 
105
<longdesc lang="en">
 
106
The number by which to multiply the number of connected ping nodes by
 
107
</longdesc>
 
108
<shortdesc lang="en">Value multiplier</shortdesc>
 
109
<content type="integer" default=""/>
 
110
</parameter>
 
111
 
 
112
<parameter name="host_list" unique="0">
 
113
<longdesc lang="en">
 
114
The list of ping nodes to count.  Defaults to all configured ping nodes.  Rarely needs to be specified.
 
115
</longdesc>
 
116
<shortdesc lang="en">Host list</shortdesc>
 
117
<content type="integer" default=""/>
 
118
</parameter>
 
119
 
 
120
<parameter name="ignore_deprecation">
 
121
<longdesc lang="en">
 
122
If set to true, suppresses the deprecation warning for this agent.
 
123
</longdesc>
 
124
<shortdesc lang="en">Suppress deprecation warning</shortdesc>
 
125
<content type="boolean" default="false" />
 
126
</parameter>
 
127
 
 
128
</parameters>
 
129
 
 
130
<actions>
 
131
<action name="start"   timeout="20s" />
 
132
<action name="stop"    timeout="20s" />
 
133
<action name="monitor" depth="0"  timeout="20s" interval="10" />
 
134
<action name="meta-data"  timeout="5" />
 
135
<action name="validate-all"  timeout="20s" />
 
136
</actions>
 
137
</resource-agent>
 
138
END
 
139
}
 
140
 
 
141
#######################################################################
 
142
 
 
143
pingd_usage() {
 
144
        cat <<END
 
145
usage: $0 {start|stop|monitor|validate-all|meta-data}
 
146
 
 
147
Expects to have a fully populated OCF RA-compliant environment set.
 
148
END
 
149
}
 
150
 
 
151
pingd_start() {
 
152
    extras=""
 
153
    if [ ! -z "$OCF_RESKEY_multiplier" ]; then
 
154
        extras="$extras -m $OCF_RESKEY_multiplier"
 
155
    fi
 
156
    if [ ! -z "$OCF_RESKEY_set" ]; then
 
157
        extras="$extras -s $OCF_RESKEY_set"
 
158
    fi
 
159
    if [ ! -z "$OCF_RESKEY_section" ]; then
 
160
        extras="$extras -S $OCF_RESKEY_section"
 
161
    fi
 
162
    for a_host in $OCF_RESKEY_host_list; do
 
163
        extras="$extras -h $a_host"
 
164
    done
 
165
    pingd_cmd="${HA_BIN}/pingd -D -p $OCF_RESKEY_pidfile -a $OCF_RESKEY_name -d $OCF_RESKEY_dampen $extras"
 
166
 
 
167
    if [ ! -z $OCF_RESKEY_user ]; then
 
168
        sudo -u $OCF_RESKEY_user $pingd_cmd
 
169
    else
 
170
        $pingd_cmd
 
171
    fi
 
172
 
 
173
    rc=$?
 
174
    if [ $rc = 0 ]; then
 
175
        exit $OCF_SUCCESS
 
176
    fi
 
177
 
 
178
    ocf_log err "Could not run $pingd_cmd : rc=$rc"
 
179
    exit $OCF_ERR_GENERIC
 
180
}
 
181
 
 
182
pingd_stop() {
 
183
    if [ -f $OCF_RESKEY_pidfile ]; then
 
184
        pid=`cat $OCF_RESKEY_pidfile`
 
185
    fi
 
186
    if [ ! -z $pid ]; then
 
187
        kill -s 9 $pid
 
188
        rc=$?
 
189
 
 
190
        if [ $rc = 0 -o $rc = 1 ]; then
 
191
            rm $OCF_RESKEY_pidfile
 
192
            exit $OCF_SUCCESS
 
193
        fi
 
194
 
 
195
        ocf_log err "Unexpected result from kill -9 $pid: $rc"
 
196
        exit $OCF_ERR_GENERIC
 
197
    fi
 
198
    exit $OCF_SUCCESS
 
199
}
 
200
 
 
201
pingd_monitor() {
 
202
    if [ -f $OCF_RESKEY_pidfile ]; then
 
203
        pid=`cat $OCF_RESKEY_pidfile`
 
204
    fi
 
205
    if [ ! -z $pid ]; then
 
206
        kill -s 0 $pid
 
207
        if [ $? = 0 ]; then
 
208
            exit $OCF_SUCCESS
 
209
        fi
 
210
    fi
 
211
    exit $OCF_NOT_RUNNING
 
212
}
 
213
 
 
214
pingd_validate() {
 
215
# Existence of the user
 
216
    if [ ! -z $OCF_RESKEY_user ]; then
 
217
        getent passwd "$OCF_RESKEY_user" >/dev/null
 
218
        if [ $? -eq 0 ]; then
 
219
            : Yes, user exists. We can further check his permission on crm_mon if necessary
 
220
        else
 
221
            ocf_log err "The user $OCF_RESKEY_user does not exist!"
 
222
            exit $OCF_ERR_ARGS
 
223
        fi
 
224
    fi
 
225
 
 
226
# Pidfile better be an absolute path
 
227
    case $OCF_RESKEY_pidfile in
 
228
        /*) ;;
 
229
        *) ocf_log warn "You should have pidfile($OCF_RESKEY_pidfile) of absolute path!" ;;
 
230
    esac
 
231
 
 
232
# Check the update interval
 
233
    if ocf_is_decimal "$OCF_RESKEY_update" && [ $OCF_RESKEY_update -gt 0 ]; then
 
234
        :
 
235
    else
 
236
        ocf_log err "Invalid update interval $OCF_RESKEY_update. It should be positive integer!"
 
237
        exit $OCF_ERR_ARGS
 
238
    fi
 
239
 
 
240
    echo "Validate OK"
 
241
    return $OCF_SUCCESS
 
242
}
 
243
 
 
244
if [ $# -ne 1 ]; then
 
245
    pingd_usage
 
246
    exit $OCF_ERR_ARGS
 
247
fi
 
248
 
 
249
: ${OCF_RESKEY_pidfile:="$HA_RSCTMP/pingd-${OCF_RESOURCE_INSTANCE}"}
 
250
: ${OCF_RESKEY_name:="pingd"}
 
251
: ${OCF_RESKEY_dampen:="1s"}
 
252
 
 
253
if [ "$__OCF_ACTION" = "meta-data" ]; then
 
254
    meta_data
 
255
    exit $OCF_SUCCESS
 
256
fi
 
257
 
 
258
# Be obnoxious, log deprecation warning on every invocation (unless
 
259
# suppressed by resource configuration).
 
260
ocf_deprecated
 
261
 
 
262
case $__OCF_ACTION in
 
263
start)          pingd_start
 
264
                ;;
 
265
stop)           pingd_stop
 
266
                ;;
 
267
monitor)        pingd_monitor
 
268
                ;;
 
269
validate-all)   pingd_validate
 
270
                ;;
 
271
usage|help)     pingd_usage
 
272
                exit $OCF_SUCCESS
 
273
                ;;
 
274
*)              pingd_usage
 
275
                exit $OCF_ERR_UNIMPLEMENTED
 
276
                ;;
 
277
esac
 
278
 
 
279
exit $?