223 lines
6.5 KiB
Bash
223 lines
6.5 KiB
Bash
#!/bin/sh
|
|
#
|
|
#
|
|
# Neutron_Legacy_HA OCF
|
|
#
|
|
# Copyright (c) 2014 Hui Xiang
|
|
# All Rights Reserved.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of version 2 of the GNU General Public License as
|
|
# published by the Free Software Foundation.
|
|
#
|
|
# This program is distributed in the hope that it would be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
#
|
|
# Further, this software is distributed without any warranty that it is
|
|
# free of the rightful claim of any third person regarding infringement
|
|
# or the like. Any license provided herein, whether implied or
|
|
# otherwise, applies only to this software file. Patent licenses, if
|
|
# any, provided herein do not apply to combinations of this program with
|
|
# other software, or any other product whatsoever.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write the Free Software Foundation,
|
|
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
|
#
|
|
|
|
#######################################################################
|
|
# Initialization:
|
|
|
|
: ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
|
|
. ${OCF_FUNCTIONS}
|
|
: ${__OCF_ACTION=$1}
|
|
|
|
#######################################################################
|
|
|
|
meta_data() {
|
|
cat <<END
|
|
<?xml version="1.0"?>
|
|
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
|
|
<resource-agent name="ping">
|
|
<version>1.0</version>
|
|
|
|
<longdesc lang="en">
|
|
Every time the monitor action is run, this resource agent records (in the CIB) the current number of ping nodes the host can connect to.
|
|
It is essentially the same as pingd except that it uses the system ping tool to obtain the results.
|
|
</longdesc>
|
|
<shortdesc lang="en">node connectivity</shortdesc>
|
|
|
|
<parameters>
|
|
|
|
<parameter name="pidfile" unique="0">
|
|
<longdesc lang="en">PID file</longdesc>
|
|
<shortdesc lang="en">PID file</shortdesc>
|
|
<content type="string" default="$HA_VARRUN/ping-${OCF_RESOURCE_INSTANCE}" />
|
|
</parameter>
|
|
|
|
<parameter name="dampen" unique="0">
|
|
<longdesc lang="en">
|
|
The time to wait (dampening) further changes occur
|
|
</longdesc>
|
|
<shortdesc lang="en">Dampening interval</shortdesc>
|
|
<content type="integer" default="5s"/>
|
|
</parameter>
|
|
|
|
<parameter name="name" unique="0">
|
|
<longdesc lang="en">
|
|
The name of the attributes to set. This is the name to be used in the constraints.
|
|
</longdesc>
|
|
<shortdesc lang="en">Attribute name</shortdesc>
|
|
<content type="string" default="pingd"/>
|
|
</parameter>
|
|
|
|
<parameter name="multiplier" unique="0">
|
|
<longdesc lang="en">
|
|
The number by which to multiply the number of connected ping nodes by
|
|
</longdesc>
|
|
<shortdesc lang="en">Value multiplier</shortdesc>
|
|
<content type="integer" default=""/>
|
|
</parameter>
|
|
|
|
<parameter name="host_list" unique="0" required="1">
|
|
<longdesc lang="en">
|
|
The list of ping nodes to count.
|
|
</longdesc>
|
|
<shortdesc lang="en">Host list</shortdesc>
|
|
<content type="string" default=""/>
|
|
</parameter>
|
|
|
|
<parameter name="attempts" unique="0">
|
|
<longdesc lang="en">
|
|
Number of ping attempts, per host, before declaring it dead
|
|
</longdesc>
|
|
<shortdesc lang="en">no. of ping attempts</shortdesc>
|
|
<content type="integer" default="2"/>
|
|
</parameter>
|
|
|
|
<parameter name="timeout" unique="0">
|
|
<longdesc lang="en">
|
|
How long, in seconds, to wait before declaring a ping lost
|
|
</longdesc>
|
|
<shortdesc lang="en">ping timeout in seconds</shortdesc>
|
|
<content type="integer" default="2"/>
|
|
</parameter>
|
|
|
|
<parameter name="options" unique="0">
|
|
<longdesc lang="en">
|
|
A catch all for any other options that need to be passed to ping.
|
|
</longdesc>
|
|
<shortdesc lang="en">Extra Options</shortdesc>
|
|
<content type="string" default=""/>
|
|
</parameter>
|
|
|
|
<parameter name="failure_score" unique="0">
|
|
<longdesc lang="en">
|
|
Resource is failed if the score is less than failure_score.
|
|
Default never fails.
|
|
</longdesc>
|
|
<shortdesc lang="en">failure_score</shortdesc>
|
|
<content type="integer" default=""/>
|
|
</parameter>
|
|
|
|
<parameter name="debug" unique="0">
|
|
<longdesc lang="en">
|
|
Enables to use default attrd_updater verbose logging on every call.
|
|
</longdesc>
|
|
<shortdesc lang="en">Verbose logging</shortdesc>
|
|
<content type="string" default="false"/>
|
|
</parameter>
|
|
|
|
</parameters>
|
|
<actions>
|
|
<action name="start" timeout="60" />
|
|
<action name="stop" timeout="20" />
|
|
<action name="reload" timeout="100" />
|
|
<action name="monitor" depth="0" timeout="60" interval="10"/>
|
|
<action name="meta-data" timeout="5" />
|
|
<action name="validate-all" timeout="30" />
|
|
</actions>
|
|
</resource-agent>
|
|
END
|
|
}
|
|
|
|
#######################################################################
|
|
OCF_RESKEY_binary_default="/usr/local/bin/monitor.py"
|
|
OCF_RESKEY_user_default="neutron"
|
|
OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid"
|
|
|
|
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
|
|
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
|
|
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
|
|
|
|
#######################################################################
|
|
|
|
MonitorNeutron_conditional_log() {
|
|
level=$1; shift
|
|
if [ ${OCF_RESKEY_debug} = "true" ]; then
|
|
ocf_log $level "$*"
|
|
fi
|
|
}
|
|
|
|
MonitorNeutron_usage() {
|
|
cat <<END
|
|
usage: $0 {start|stop|migrate_to|migrate_from|validate-all|meta-data}
|
|
|
|
Expects to have a fully populated OCF RA-compliant environment set.
|
|
END
|
|
}
|
|
|
|
MonitorNeutron_start() {
|
|
echo "MonitorNeutron_start"
|
|
su ${OCF_RESKEY_user} -s /bin/sh -c "python ${OCF_RESKEY_binary} $OCF_RESKEY_additional_parameters" \
|
|
' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid
|
|
|
|
ping_monitor
|
|
if [ $? = $OCF_SUCCESS ]; then
|
|
return $OCF_SUCCESS
|
|
fi
|
|
|
|
ocf_log info "MonitorNeutron started"
|
|
}
|
|
|
|
MonitorNeutron_stop() {
|
|
# Try SIGTERM
|
|
pid=`cat $OCF_RESKEY_pid`
|
|
ocf_run kill -s TERM $pid
|
|
rc=$?
|
|
if [ $rc -ne 0 ]; then
|
|
ocf_log err "MonitorNeutron couldn't be stopped"
|
|
exit $OCF_ERR_GENERIC
|
|
fi
|
|
|
|
ocf_log info "MonitorNeutron stopped"
|
|
return $OCF_SUCCESS
|
|
}
|
|
|
|
MonitorNeutron_validate() {
|
|
# Is the state directory writable?
|
|
if [ ! -f $OCF_RESKEY_binary ]; then
|
|
ocf_log err "No file $OCF_RESKEY_binary exists !"
|
|
return $OCF_ERRARGS
|
|
fi
|
|
return $OCF_SUCCESS
|
|
}
|
|
|
|
case $__OCF_ACTION in
|
|
meta-data) meta_data
|
|
exit $OCF_SUCCESS
|
|
;;
|
|
start) MonitorNeutron_start;;
|
|
stop) MonitorNeutron_stop;;
|
|
reload) MonitorNeutron_start;;
|
|
validate-all) MonitorNeutron_validate;;
|
|
usage|help) MonitorNeutron_usage
|
|
exit $OCF_SUCCESS
|
|
;;
|
|
*) MonitorNeutron_usage
|
|
exit $OCF_ERR_UNIMPLEMENTED
|
|
;;
|
|
esac
|
|
exit $?
|