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

« back to all changes in this revision

Viewing changes to heartbeat/Dummy

  • 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
#       Dummy 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
 
 
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="Dummy" version="0.9">
 
43
<version>1.0</version>
 
44
 
 
45
<longdesc lang="en">
 
46
This is a Dummy Resource Agent. It does absolutely nothing except 
 
47
keep track of whether its running or not.
 
48
Its purpose in life is for testing and to serve as a template for RA writers.
 
49
 
 
50
NB: Please pay attention to the timeouts specified in the actions
 
51
section below. They should be meaningful for the kind of resource
 
52
the agent manages. They should be the minimum advised timeouts,
 
53
but they shouldn't/cannot cover _all_ possible resource
 
54
instances. So, try to be neither overly generous nor too stingy,
 
55
but moderate. The minimum timeouts should never be below 10 seconds.
 
56
</longdesc>
 
57
<shortdesc lang="en">Example stateless resource agent</shortdesc>
 
58
 
 
59
<parameters>
 
60
<parameter name="state" unique="1">
 
61
<longdesc lang="en">
 
62
Location to store the resource state in.
 
63
</longdesc>
 
64
<shortdesc lang="en">State file</shortdesc>
 
65
<content type="string" default="${HA_RSCTMP}/Dummy-${OCF_RESOURCE_INSTANCE}.state" />
 
66
</parameter>
 
67
 
 
68
<parameter name="fake" unique="0">
 
69
<longdesc lang="en">
 
70
Fake attribute that can be changed to cause a reload
 
71
</longdesc>
 
72
<shortdesc lang="en">Fake attribute that can be changed to cause a reload</shortdesc>
 
73
<content type="string" default="dummy" />
 
74
</parameter>
 
75
 
 
76
</parameters>
 
77
 
 
78
<actions>
 
79
<action name="start"        timeout="20" />
 
80
<action name="stop"         timeout="20" />
 
81
<action name="monitor"      timeout="20" interval="10" depth="0" />
 
82
<action name="reload"       timeout="20" />
 
83
<action name="migrate_to"   timeout="20" />
 
84
<action name="migrate_from" timeout="20" />
 
85
<action name="meta-data"    timeout="5" />
 
86
<action name="validate-all"   timeout="20" />
 
87
</actions>
 
88
</resource-agent>
 
89
END
 
90
}
 
91
 
 
92
#######################################################################
 
93
 
 
94
dummy_usage() {
 
95
        cat <<END
 
96
usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data}
 
97
 
 
98
Expects to have a fully populated OCF RA-compliant environment set.
 
99
END
 
100
}
 
101
 
 
102
dummy_start() {
 
103
    dummy_monitor
 
104
    if [ $? =  $OCF_SUCCESS ]; then
 
105
        return $OCF_SUCCESS
 
106
    fi
 
107
    touch ${OCF_RESKEY_state}
 
108
}
 
109
 
 
110
dummy_stop() {
 
111
    dummy_monitor
 
112
    if [ $? =  $OCF_SUCCESS ]; then
 
113
        rm ${OCF_RESKEY_state}
 
114
    fi
 
115
    return $OCF_SUCCESS
 
116
}
 
117
 
 
118
dummy_monitor() {
 
119
        # Monitor _MUST!_ differentiate correctly between running
 
120
        # (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING).
 
121
        # That is THREE states, not just yes/no.
 
122
        
 
123
        if [ -f ${OCF_RESKEY_state} ]; then
 
124
            return $OCF_SUCCESS
 
125
        fi
 
126
        if false ; then
 
127
                return $OCF_ERR_GENERIC
 
128
        fi
 
129
        return $OCF_NOT_RUNNING
 
130
}
 
131
 
 
132
dummy_validate() {
 
133
    
 
134
    # Is the state directory writable? 
 
135
    state_dir=`dirname "$OCF_RESKEY_state"`
 
136
    touch "$state_dir/$$"
 
137
    if [ $? != 0 ]; then
 
138
        return $OCF_ERR_ARGS
 
139
    fi
 
140
    rm "$state_dir/$$"
 
141
 
 
142
    return $OCF_SUCCESS
 
143
}
 
144
 
 
145
: ${OCF_RESKEY_state=${HA_RSCTMP}/Dummy-${OCF_RESOURCE_INSTANCE}.state}
 
146
: ${OCF_RESKEY_fake="dummy"}
 
147
 
 
148
case $__OCF_ACTION in
 
149
meta-data)      meta_data
 
150
                exit $OCF_SUCCESS
 
151
                ;;
 
152
start)          dummy_start;;
 
153
stop)           dummy_stop;;
 
154
monitor)        dummy_monitor;;
 
155
migrate_to)     ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_target}."
 
156
                dummy_stop
 
157
                ;;
 
158
migrate_from)   ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} from ${OCF_RESKEY_CRM_meta_migrate_source}."
 
159
                dummy_start
 
160
                ;;
 
161
reload)         ocf_log info "Reloading ${OCF_RESOURCE_INSTANCE} ..."
 
162
                ;;
 
163
validate-all)   dummy_validate;;
 
164
usage|help)     dummy_usage
 
165
                exit $OCF_SUCCESS
 
166
                ;;
 
167
*)              dummy_usage
 
168
                exit $OCF_ERR_UNIMPLEMENTED
 
169
                ;;
 
170
esac
 
171
rc=$?
 
172
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
 
173
exit $rc
 
174