4
# Support: linux-ha@lists.linux-ha.org
5
# License: GNU General Public License (GPL)
7
# This script is a test resource for introducing delay.
9
# usage: $0 {start|stop|status|monitor|meta-data}
11
# OCF parameters are as below:
12
# OCF_RESKEY_startdelay
13
# OCF_RESKEY_stopdelay
17
# OCF_RESKEY_startdelay defaults to 30 (seconds)
18
# OCF_RESKEY_stopdelay defaults to $OCF_RESKEY_startdelay
19
# OCF_RESKEY_mondelay defaults to $OCF_RESKEY_startdelay
22
# This is really a test resource script.
25
#######################################################################
28
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
29
. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
31
#######################################################################
35
usage: $0 {start|stop|status|monitor|meta-data|validate-all}
42
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
43
<resource-agent name="Delay">
44
<version>1.0</version>
47
This script is a test resource for introducing delay.
49
<shortdesc lang="en">Waits for a defined timespan</shortdesc>
53
<parameter name="startdelay" unique="0" required="0">
55
How long in seconds to delay on start operation.
57
<shortdesc lang="en">Start delay</shortdesc>
58
<content type="integer" default="30" />
61
<parameter name="stopdelay" unique="0" required="0">
63
How long in seconds to delay on stop operation.
64
Defaults to "startdelay" if unspecified.
66
<shortdesc lang="en">Stop delay</shortdesc>
67
<content type="integer" default="30" />
70
<parameter name="mondelay" unique="0" required="0">
72
How long in seconds to delay on monitor operation.
73
Defaults to "startdelay" if unspecified.
75
<shortdesc lang="en">Monitor delay</shortdesc>
76
<content type="integer" default="30" />
81
<action name="start" timeout="30" />
82
<action name="stop" timeout="30" />
83
<action name="status" depth="0" timeout="30" interval="10" />
84
<action name="monitor" depth="0" timeout="30" interval="10" />
85
<action name="meta-data" timeout="5" />
86
<action name="validate-all" timeout="5" />
93
ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} monitor
100
ocf_log info "Delay is running OK"
103
ocf_log info "Delay is stopped"
104
return $OCF_NOT_RUNNING
109
Delay_Validate_All -q
110
sleep $OCF_RESKEY_mondelay
118
ocf_log info "Delay already running."
121
Delay_Validate_All -q
122
ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} start
124
sleep $OCF_RESKEY_startdelay
138
Delay_Validate_All -q
139
ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} stop
141
sleep $OCF_RESKEY_stopdelay
149
ocf_log info "Delay already stopped."
154
# Check if all the arguments are valid numbers, a string is considered valid if:
155
# 1. It does not contain any character but digits and period ".";
156
# 2. The period "." does not occur more than once
158
Are_Valid_Numbers() {
160
echo $i |grep -v [^0-9.] |grep -q -v [.].*[.]
161
if test $? -ne 0; then
168
Delay_Validate_All() {
169
# Be quiet when specified -q option _and_ validation succeded
172
if test $option = "q"; then
177
shift $(($OPTIND -1))
179
if Are_Valid_Numbers $OCF_RESKEY_startdelay $OCF_RESKEY_stopdelay \
180
$OCF_RESKEY_mondelay; then
181
if test $quiet = "no"; then
184
# _Return_ on validation success
187
echo "Some of the instance parameters are invalid"
188
# _Exit_ on validation failure
193
if [ $# -ne 1 ]; then
198
: ${OCF_RESKEY_startdelay=30}
199
: ${OCF_RESKEY_stopdelay=$OCF_RESKEY_startdelay}
200
: ${OCF_RESKEY_mondelay=$OCF_RESKEY_startdelay}
210
monitor) Delay_Monitor
214
validate-all) Delay_Validate_All