4 # ClusterNotify OCF RA.
5 # Starts crm_mon in background which logs cluster status as
6 # html to the specified file.
8 # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Bré All Rights Reserved.
9 # Copyright (c) 2012 Grueninger GmbH, Andreas Grueninger All Rights Reserved.
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.
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.
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.
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.
29 # OCF instance parameters:
32 # OCF_RESKEY_extra_options
34 ################### Test
35 # cf-tester -v -n ClusterNotify-1 \
36 # -o extra_options="-ls -m 10.50.235.1" -o pidfile=/opt/ha/var/run/test.pid \
37 # clusternode/opt/ha/lib/ocf/resource.d/lgl/ClusterNotify
40 #######################################################################
42 : ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
46 #######################################################################
51 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
52 <resource-agent name="ClusterNotify">
53 <version>1.0</version>
56 This is a ClusterNotify Resource Agent.
57 It outputs current cluster status to an SNMP manager or as DBUS events.
59 <shortdesc lang="en">Runs corosync-notifyd in the background, recording the cluster status to an SNMP manager or as DBUS events</shortdesc>
63 <parameter name="user" unique="0">
65 The user we want to run corosync-notifyd as
67 <shortdesc lang="en">The user we want to run corosync-notifyd as</shortdesc>
68 <content type="string" default="root" />
71 <parameter name="extra_options" unique="0">
73 Additional options to pass to corosync-notifyd. Eg. -lsm <SNMP manager>
75 <shortdesc lang="en">Extra options</shortdesc>
76 <content type="string" default="" />
79 <parameter name="pidfile" unique="1">
81 PID file location to ensure only one instance is running
83 <shortdesc lang="en">PID file</shortdesc>
84 <content type="string" default="/tmp/ClusterNotify_${OCF_RESOURCE_INSTANCE}.pid" />
90 <action name="start" timeout="20" />
91 <action name="stop" timeout="20" />
92 <action name="monitor" depth="0" timeout="20" interval="10" />
93 <action name="meta-data" timeout="5" />
94 <action name="validate-all" timeout="30" />
100 #######################################################################
102 ClusterNotify_usage
() {
104 usage: $0 {start|stop|monitor|validate-all|meta-data}
106 Expects to have a fully populated OCF RA-compliant environment set.
109 ClusterNotify_killAll
() {
112 if [ "x$pid" != "x" ]; then
118 ClusterNotify_getPID
() {
123 ocf_log debug
"line <- ps -ef -o pid,args|grep \"${ClusterNotify_cmdline}\"|grep -v grep"
124 line
=`ps -ef -o pid,args|grep "${ClusterNotify_cmdline}"|grep -v grep`
125 if [ "$i{line}x" != "x" ]; then
126 IFS
=" " && words
=($line)
127 if [ "${words[0]}"x
!= ""x
]; then
128 ClusterNotify_pid
=${words[0]}
133 ClusterNotify_start
() {
136 if [ ! -z $OCF_RESKEY_user ]; then
137 su
- $OCF_RESKEY_user -c "${ClusterNotify_cmdline}"
139 ${ClusterNotify_cmdline}
142 if [ $ClusterNotify_pid = -1 ]; then
143 return $OCF_ERR_GENERIC
145 echo $ClusterNotify_pid>$OCF_RESKEY_pidfile
150 ClusterNotify_stop
() {
152 if [ -f $OCF_RESKEY_pidfile ]; then
153 pid
=`cat $OCF_RESKEY_pidfile`
154 if [ "x$pid" != "x" ]; then
156 rm -f $OCF_RESKEY_pidfile
159 # ClusterNotify_killAll
163 ClusterNotify_monitor
() {
165 if [ -f $OCF_RESKEY_pidfile ]; then
166 pid
=`cat $OCF_RESKEY_pidfile`
167 if [ "x$pid" != "x" ]; then
169 if [ "$ClusterNotify_pid" != "$pid" ]; then
170 rm -f $OCF_RESKEY_pidfile
172 kill -s 0 $pid >/dev
/null
2>&1; rc
=$?
174 0) return $OCF_SUCCESS;;
175 1) return $OCF_NOT_RUNNING;;
176 *) return $OCF_ERR_GENERIC;;
180 return $OCF_NOT_RUNNING
183 ClusterNotify_validate
() {
184 # Existence of the user
185 if [ ! -z $OCF_RESKEY_user ]; then
186 getent passwd
"$OCF_RESKEY_user" >/dev
/null
187 if [ $?
-eq 0 ]; then
188 : Yes
, user exists. We can further check his permission on crm_mon
if necessary
190 ocf_log err
"The user $OCF_RESKEY_user does not exist!"
195 # Pidfile better be an absolute path
196 case $OCF_RESKEY_pidfile in
198 *) ocf_log warn
"You should have pidfile($OCF_RESKEY_pidfile) of absolute path!" ;;
205 if [ $# -ne 1 ]; then
210 : ${OCF_RESKEY_pidfile:="/tmp/ClusterNotify_${OCF_RESOURCE_INSTANCE}.pid"}
213 ClusterNotify_cmdline
="${HA_SBIN_DIR}/corosync-notifyd $OCF_RESKEY_extra_options"
215 case $__OCF_ACTION in
219 start
) ClusterNotify_start
221 stop
) ClusterNotify_stop
223 monitor
) ClusterNotify_monitor
225 validate-all
) ClusterNotify_validate
227 usage|
help) ClusterNotify_usage
230 *) ClusterNotify_usage
231 return $OCF_ERR_UNIMPLEMENTED