rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / cluster / resource-agents-openindiana / files / ClusterNotify
blobbcbb8f16e7af33ae69ec250ef278a699bc2f4169
1 #!/bin/bash
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:
30 # OCF_RESKEY_user
31 # OCF_RESKEY_pidfile
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
38 ###################
40 #######################################################################
41 # Initialization:
42 : ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
43 . ${OCF_FUNCTIONS}
44 : ${__OCF_ACTION=$1}
46 #######################################################################
48 meta_data() {
49 cat <<END
50 <?xml version="1.0"?>
51 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
52 <resource-agent name="ClusterNotify">
53 <version>1.0</version>
55 <longdesc lang="en">
56 This is a ClusterNotify Resource Agent.
57 It outputs current cluster status to an SNMP manager or as DBUS events.
58 </longdesc>
59 <shortdesc lang="en">Runs corosync-notifyd in the background, recording the cluster status to an SNMP manager or as DBUS events</shortdesc>
61 <parameters>
63 <parameter name="user" unique="0">
64 <longdesc lang="en">
65 The user we want to run corosync-notifyd as
66 </longdesc>
67 <shortdesc lang="en">The user we want to run corosync-notifyd as</shortdesc>
68 <content type="string" default="root" />
69 </parameter>
71 <parameter name="extra_options" unique="0">
72 <longdesc lang="en">
73 Additional options to pass to corosync-notifyd. Eg. -lsm &lt;SNMP manager&gt;
74 </longdesc>
75 <shortdesc lang="en">Extra options</shortdesc>
76 <content type="string" default="" />
77 </parameter>
79 <parameter name="pidfile" unique="1">
80 <longdesc lang="en">
81 PID file location to ensure only one instance is running
82 </longdesc>
83 <shortdesc lang="en">PID file</shortdesc>
84 <content type="string" default="/tmp/ClusterNotify_${OCF_RESOURCE_INSTANCE}.pid" />
85 </parameter>
87 </parameters>
89 <actions>
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" />
95 </actions>
96 </resource-agent>
97 END
100 #######################################################################
102 ClusterNotify_usage() {
103 cat <<END
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() {
110 local pid
111 pid=`pgrep -f "$1"`
112 if [ "x$pid" != "x" ]; then
113 kill -9 $pid
115 return $OCF_SUCCESS
118 ClusterNotify_getPID() {
119 local line
120 local words
121 ClusterNotify_pid=-1
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() {
134 local cmd_prefix=""
135 local cmd_suffix=""
136 if [ ! -z $OCF_RESKEY_user ]; then
137 su - $OCF_RESKEY_user -c "${ClusterNotify_cmdline}"
138 else
139 ${ClusterNotify_cmdline}
141 ClusterNotify_getPID
142 if [ $ClusterNotify_pid = -1 ]; then
143 return $OCF_ERR_GENERIC
144 else
145 echo $ClusterNotify_pid>$OCF_RESKEY_pidfile
146 return $OCF_SUCCESS
150 ClusterNotify_stop() {
151 local pid
152 if [ -f $OCF_RESKEY_pidfile ]; then
153 pid=`cat $OCF_RESKEY_pidfile`
154 if [ "x$pid" != "x" ]; then
155 kill -s 9 $pid
156 rm -f $OCF_RESKEY_pidfile
159 # ClusterNotify_killAll
160 return $OCF_SUCCESS
163 ClusterNotify_monitor() {
164 local pid
165 if [ -f $OCF_RESKEY_pidfile ]; then
166 pid=`cat $OCF_RESKEY_pidfile`
167 if [ "x$pid" != "x" ]; then
168 ClusterNotify_getPID
169 if [ "$ClusterNotify_pid" != "$pid" ]; then
170 rm -f $OCF_RESKEY_pidfile
172 kill -s 0 $pid >/dev/null 2>&1; rc=$?
173 case $rc in
174 0) return $OCF_SUCCESS;;
175 1) return $OCF_NOT_RUNNING;;
176 *) return $OCF_ERR_GENERIC;;
177 esac
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
189 else
190 ocf_log err "The user $OCF_RESKEY_user does not exist!"
191 return $OCF_ERR_ARGS
195 # Pidfile better be an absolute path
196 case $OCF_RESKEY_pidfile in
197 /*) ;;
198 *) ocf_log warn "You should have pidfile($OCF_RESKEY_pidfile) of absolute path!" ;;
199 esac
201 echo "Validate OK"
202 return $OCF_SUCCESS
205 if [ $# -ne 1 ]; then
206 ClusterNotify_usage
207 return $OCF_ERR_ARGS
210 : ${OCF_RESKEY_pidfile:="/tmp/ClusterNotify_${OCF_RESOURCE_INSTANCE}.pid"}
212 ClusterNotify_pid=0
213 ClusterNotify_cmdline="${HA_SBIN_DIR}/corosync-notifyd $OCF_RESKEY_extra_options"
215 case $__OCF_ACTION in
216 meta-data) meta_data
217 return $OCF_SUCCESS
219 start) ClusterNotify_start
221 stop) ClusterNotify_stop
223 monitor) ClusterNotify_monitor
225 validate-all) ClusterNotify_validate
227 usage|help) ClusterNotify_usage
228 return $OCF_SUCCESS
230 *) ClusterNotify_usage
231 return $OCF_ERR_UNIMPLEMENTED
233 esac
235 exit $?