Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/extra/resources/ClusterMon.in b/extra/resources/ClusterMon.in
index 654097a6fc..c6b0bac068 100755
--- a/extra/resources/ClusterMon.in
+++ b/extra/resources/ClusterMon.in
@@ -1,262 +1,262 @@
#!@BASH_PATH@
#
# ocf:pacemaker:ClusterMon resource agent
#
# Original copyright 2004 SUSE LINUX AG, Lars Marowsky-Br<E9>e
# Later changes copyright 2008-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
# Starts crm_mon in background which logs cluster status as
# html to the specified file.
#
# OCF instance parameters:
# OCF_RESKEY_user
# OCF_RESKEY_pidfile
# OCF_RESKEY_update
# OCF_RESKEY_extra_options
# OCF_RESKEY_htmlfile
#######################################################################
# 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="ClusterMon" version="1.0">
<version>1.0</version>
<longdesc lang="en">
This is a ClusterMon Resource Agent.
It outputs current cluster status to the html.
</longdesc>
<shortdesc lang="en">Runs crm_mon in the background, recording the cluster status to an HTML file</shortdesc>
<parameters>
<parameter name="user" unique="0">
<longdesc lang="en">
The user we want to run crm_mon as
</longdesc>
<shortdesc lang="en">The user we want to run crm_mon as</shortdesc>
<content type="string" default="root" />
</parameter>
<parameter name="update" unique="0">
<longdesc lang="en">
How frequently should we update the cluster status (in milliseconds).
For compatibility with old documentation, values less than 1000 will be treated
as seconds.
</longdesc>
<shortdesc lang="en">Update interval in milliseconds</shortdesc>
<content type="integer" default="15000" />
</parameter>
<parameter name="extra_options" unique="0">
<longdesc lang="en">
Additional options to pass to crm_mon. Eg. -n -r
</longdesc>
<shortdesc lang="en">Extra options</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="pidfile" unique="1">
<longdesc lang="en">
PID file location to ensure only one instance is running
</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.pid" />
</parameter>
<parameter name="htmlfile" unique="1" required="0">
<longdesc lang="en">
Location to write HTML output to.
</longdesc>
<shortdesc lang="en">HTML output</shortdesc>
<content type="string" default="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.html" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="20s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
}
#######################################################################
ClusterMon_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
ClusterMon_exit() {
- if [ $1 != 0 ]; then
+ if [ $1 -ne 0 ]; then
exit $OCF_ERR_GENERIC
else
exit $OCF_SUCCESS
fi
}
ClusterMon_start() {
- if [ ! -z "$OCF_RESKEY_user" ]; then
+ if [ -n "$OCF_RESKEY_user" ]; then
su - "$OCF_RESKEY_user" -c "$CMON_CMD"
else
eval $CMON_CMD
fi
ClusterMon_exit $?
}
ClusterMon_stop() {
if [ -f "$OCF_RESKEY_pidfile" ]; then
pid=$(cat "$OCF_RESKEY_pidfile")
- if [ ! -z "$pid" ]; then
+ if [ -n "$pid" ]; then
kill -s 9 $pid
rm -f "$OCF_RESKEY_pidfile"
fi
fi
ClusterMon_exit 0
}
ClusterMon_monitor() {
if [ -f "$OCF_RESKEY_pidfile" ]; then
pid=$(cat "$OCF_RESKEY_pidfile")
- if [ ! -z "$pid" ]; then
+ if [ -n "$pid" ]; then
str=$(echo "su - \"$OCF_RESKEY_user\" -c \"$CMON_CMD\"" | tr 'crmon, \t' 'xxxxxxxx')
ps -o "args=${str}" -p $pid 2>/dev/null | \
grep -qE "[c]rm_mon.*${OCF_RESKEY_pidfile}"
rc=$?
case $rc in
0) exit $OCF_SUCCESS;;
1) exit $OCF_NOT_RUNNING;;
*) exit $OCF_ERR_GENERIC;;
esac
fi
fi
exit $OCF_NOT_RUNNING
}
CheckOptions() {
while getopts Vi:nrh:cdp: OPTION
do
case "$OPTION" in
V|n|r|c|d);;
i) ocf_log warn "You should not have specified the -i option, since OCF_RESKEY_update is set already!";;
h) ocf_log warn "You should not have specified the -h option, since OCF_RESKEY_htmlfile is set already!";;
p) ocf_log warn "You should not have specified the -p option, since OCF_RESKEY_pidfile is set already!";;
*) return $OCF_ERR_ARGS;;
esac
done
if [ $? -ne 0 ]; then
return $OCF_ERR_ARGS
fi
# We should have eaten all options at this stage
shift $(($OPTIND -1))
if [ $# -gt 0 ]; then
false
else
true
fi
}
ClusterMon_validate() {
# Existence of the user
- if [ ! -z "$OCF_RESKEY_user" ]; then
+ if [ -n "$OCF_RESKEY_user" ]; then
getent passwd "$OCF_RESKEY_user" >/dev/null
if [ $? -eq 0 ]; then
: Yes, user exists. We can further check his permission on crm_mon if necessary
else
ocf_log err "The user $OCF_RESKEY_user does not exist!"
exit $OCF_ERR_ARGS
fi
fi
# Pidfile better be an absolute path
case "$OCF_RESKEY_pidfile" in
/*) ;;
*) ocf_log warn "You should have pidfile($OCF_RESKEY_pidfile) of absolute path!" ;;
esac
# Check the update interval
if ocf_is_decimal "$OCF_RESKEY_update" && [ $OCF_RESKEY_update -gt 0 ]; then
:
else
ocf_log err "Invalid update interval $OCF_RESKEY_update. It should be positive integer!"
exit $OCF_ERR_ARGS
fi
if CheckOptions $OCF_RESKEY_extra_options; then
:
else
ocf_log err "Invalid options $OCF_RESKEY_extra_options!"
exit $OCF_ERR_ARGS
fi
# Htmlfile better be an absolute path
case "$OCF_RESKEY_htmlfile" in
/*) ;;
*) ocf_log warn "You should have htmlfile($OCF_RESKEY_htmlfile) of absolute path!" ;;
esac
echo "Validate OK"
return $OCF_SUCCESS
}
if [ $# -ne 1 ]; then
ClusterMon_usage
exit $OCF_ERR_ARGS
fi
: ${OCF_RESKEY_update:="15000"}
: ${OCF_RESKEY_pidfile:="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.pid"}
: ${OCF_RESKEY_htmlfile:="/tmp/ClusterMon_${OCF_RESOURCE_INSTANCE}.html"}
if [ ${OCF_RESKEY_update} -ge 1000 ]; then
OCF_RESKEY_update=$(( $OCF_RESKEY_update / 1000 ))
fi
CMON_CMD="${HA_SBIN_DIR}/crm_mon -p \"$OCF_RESKEY_pidfile\" -d -i $OCF_RESKEY_update $OCF_RESKEY_extra_options -h \"$OCF_RESKEY_htmlfile\""
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) ClusterMon_start
;;
stop) ClusterMon_stop
;;
monitor) ClusterMon_monitor
;;
validate-all) ClusterMon_validate
;;
usage|help) ClusterMon_usage
exit $OCF_SUCCESS
;;
*) ClusterMon_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/HealthCPU b/extra/resources/HealthCPU
index ee73f32128..0f32c5c183 100755
--- a/extra/resources/HealthCPU
+++ b/extra/resources/HealthCPU
@@ -1,199 +1,199 @@
#!/bin/sh
#
# ocf:pacemaker:HealthCPU resource agent
#
# Copyright 2004-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#
# Measures CPUs idling and writes #health-cpu status into the CIB
#
################################
#
# TODO: Enter default values
# Error handling in getting uptime
#
##################################
#######################################################################
# 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="HealthCPU" version="0.1">
<version>1.0</version>
<longdesc lang="en">
Systhem health agent that measures the CPU idling and updates the #health-cpu attribute.
</longdesc>
<shortdesc lang="en">System health CPU usage</shortdesc>
<parameters>
<parameter name="state" unique="1">
<longdesc lang="en">
Location to store the resource state in.
</longdesc>
<shortdesc lang="en">State file</shortdesc>
<content type="string" default="${HA_VARRUN%%/}/health-cpu-${OCF_RESOURCE_INSTANCE}.state" />
</parameter>
<parameter name="yellow_limit" unique="1">
<longdesc lang="en">
Lower (!) limit of idle percentage to switch the health attribute to yellow. I.e.
the #health-cpu will go yellow if the %idle of the CPU falls below 50%.
</longdesc>
<shortdesc lang="en">Lower limit for yellow health attribute</shortdesc>
<content type="string" default="50"/>
</parameter>
<parameter name="red_limit" unique="1">
<longdesc lang="en">
Lower (!) limit of idle percentage to switch the health attribute to red. I.e.
the #health-cpu will go red if the %idle of the CPU falls below 10%.
</longdesc>
<shortdesc lang="en">Lower limit for red health attribute</shortdesc>
<content type="string" default="10"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="10s" />
<action name="stop" timeout="10s" />
<action name="monitor" timeout="10s" interval="10s" start-delay="0s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="10s" />
</actions>
</resource-agent>
END
}
#######################################################################
dummy_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
dummy_start() {
dummy_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
touch "${OCF_RESKEY_state}"
}
dummy_stop() {
dummy_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
rm "${OCF_RESKEY_state}"
fi
return $OCF_SUCCESS
}
dummy_monitor() {
# Monitor _MUST!_ differentiate correctly between running
# (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING).
# That is THREE states, not just yes/no.
if [ -f "${OCF_RESKEY_state}" ]; then
IDLE=$(top -b -n2 | grep Cpu | tail -1 | awk -F",|.[0-9][ %]id" '{ print $4 }')
# echo "System idle: " $IDLE
# echo "$OCF_RESKEY_red_limit"
# echo $OCF_RESKEY_yellow_limit
if [ $IDLE -lt ${OCF_RESKEY_red_limit} ] ; then
# echo "System state RED!"
attrd_updater -n "#health-cpu" -U "red" -d "30s"
return $OCF_SUCCESS
fi
if [ $IDLE -lt ${OCF_RESKEY_yellow_limit} ] ; then
# echo "System state yellow."
attrd_updater -n "#health-cpu" -U "yellow" -d "30s"
else
# echo "System state green."
attrd_updater -n "#health-cpu" -U "green" -d "30s"
fi
return $OCF_SUCCESS
fi
if false ; then
return $OCF_ERR_GENERIC
fi
return $OCF_NOT_RUNNING
}
dummy_validate() {
# Is the state directory writable?
state_dir=$(dirname "$OCF_RESKEY_state")
touch "$state_dir/$$"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
return $OCF_ERR_ARGS
fi
rm "$state_dir/$$"
return $OCF_SUCCESS
}
: ${OCF_RESKEY_CRM_meta_interval:=0}
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
-if [ "x$OCF_RESKEY_state" = "x" ]; then
+if [ -z "$OCF_RESKEY_state" ]; then
if [ "${OCF_RESKEY_CRM_meta_globally_unique}" = "false" ]; then
state="${HA_VARRUN%%/}/Dummy-${OCF_RESOURCE_INSTANCE}.state"
# Strip off the trailing clone marker
OCF_RESKEY_state=$(echo $state | sed s/:[0-9][0-9]*\.state/.state/)
else
OCF_RESKEY_state="${HA_VARRUN%%/}/Dummy-${OCF_RESOURCE_INSTANCE}.state"
fi
fi
-if [ "x${OCF_RESKEY_red_limit}" = "x" ] ; then
+if [ -z "${OCF_RESKEY_red_limit}" ] ; then
OCF_RESKEY_red_limit=10
fi
-if [ "x${OCF_RESKEY_yellow_limit}" = "x" ] ; then
+if [ -z "${OCF_RESKEY_yellow_limit}" ] ; then
OCF_RESKEY_yellow_limit=50
fi
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) dummy_start;;
stop) dummy_stop;;
monitor) dummy_monitor;;
validate-all) dummy_validate;;
usage|help) dummy_usage
exit $OCF_SUCCESS
;;
*) dummy_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/HealthIOWait b/extra/resources/HealthIOWait
index 4110d38cc7..9e292b4f5a 100755
--- a/extra/resources/HealthIOWait
+++ b/extra/resources/HealthIOWait
@@ -1,178 +1,178 @@
#!/bin/sh
#
# ocf:pacemaker:HealthIOWait resource agent
#
# Copyright 2004-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#
# Measures CPU iowait % via top and writes #health-iowait status into the CIB
#
#######################################################################
# 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="HealthIOWait" version="1.0">
<version>1.0</version>
<longdesc lang="en">
Systhem health agent that measures the CPU iowait via top and updates the #health-iowait attribute.
</longdesc>
<shortdesc lang="en">System health based on CPU iowait measurement</shortdesc>
<parameters>
<parameter name="state" unique="1">
<longdesc lang="en">
Location to store the resource state in.
</longdesc>
<shortdesc lang="en">State file</shortdesc>
<content type="string" default="${HA_VARRUN%%/}/health-iowait-${OCF_RESOURCE_INSTANCE}.state" />
</parameter>
<parameter name="yellow_limit" unique="0">
<longdesc lang="en">
Upper limit of iowait percentage to switch the health attribute to yellow. I.e.
the #health-iowait will go yellow if the %iowait of the CPU gets higher than 10%.
</longdesc>
<shortdesc lang="en">Upper limit for yellow health attribute</shortdesc>
<content type="string" default="10"/>
</parameter>
<parameter name="red_limit" unique="0">
<longdesc lang="en">
Upper limit of iowait percentage to switch the health attribute to red. I.e.
the #health-iowait will go red if the %iowait of the CPU get higher than 15%.
</longdesc>
<shortdesc lang="en">Upper limit for red health attribute</shortdesc>
<content type="string" default="15"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="10s" />
<action name="stop" timeout="10s" />
<action name="monitor" timeout="10s" interval="10s" start-delay="0s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="10s" />
</actions>
</resource-agent>
END
}
#######################################################################
agent_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
agent_start() {
agent_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
touch "${OCF_RESKEY_state}"
}
agent_stop() {
agent_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
rm "${OCF_RESKEY_state}"
fi
return $OCF_SUCCESS
}
agent_monitor() {
# Monitor _MUST!_ differentiate correctly between running
# (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING).
# That is THREE states, not just yes/no.
if [ -f "${OCF_RESKEY_state}" ]; then
WAIT=$(top -b -n2 | grep Cpu | tail -1 | awk -F",|.[0-9][ %]wa" '{ print $5 }')
# echo "System iowait: " $WAIT
# echo $OCF_RESKEY_yellow_limit
if [ $WAIT -gt ${OCF_RESKEY_red_limit} ] ; then
# echo "System state RED!"
attrd_updater -n "#health-iowait" -U "red" -d "5s"
return $OCF_SUCCESS
fi
if [ $WAIT -gt ${OCF_RESKEY_yellow_limit} ] ; then
# echo "System state yellow."
attrd_updater -n "#health-iowait" -U "yellow" -d "5s"
else
# echo "System state green."
attrd_updater -n "#health-iowait" -U "green" -d "5s"
fi
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
agent_validate() {
# Is the state directory writable?
state_dir=$(dirname "$OCF_RESKEY_state")
if [ -d "$state_dir" ] && [ -w "$state_dir" ] && [ -x "$state_dir" ]; then
return $OCF_ERR_ARGS
fi
return $OCF_SUCCESS
}
: ${OCF_RESKEY_CRM_meta_interval:=0}
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
-if [ "x$OCF_RESKEY_state" = "x" ]; then
+if [ -z "$OCF_RESKEY_state" ]; then
if [ "${OCF_RESKEY_CRM_meta_globally_unique}" = "false" ]; then
state="${HA_VARRUN%%/}/HealthIoWait-${OCF_RESOURCE_INSTANCE}.state"
#Strip off the trailing clone marker
OCF_RESKEY_state=$(echo $state | sed s/:[0-9][0-9]*\.state/.state/)
else
OCF_RESKEY_state="${HA_VARRUN%%/}/HealthIoWait-${OCF_RESOURCE_INSTANCE}.state"
fi
fi
-if [ "x${OCF_RESKEY_red_limit}" = "x" ] ; then
+if [ -z "${OCF_RESKEY_red_limit}" ] ; then
OCF_RESKEY_red_limit=15
fi
-if [ "x${OCF_RESKEY_yellow_limit}" = "x" ] ; then
+if [ -z "${OCF_RESKEY_yellow_limit}" ] ; then
OCF_RESKEY_yellow_limit=10
fi
case $__OCF_ACTION in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) agent_start;;
stop) agent_stop;;
monitor) agent_monitor;;
validate-all) agent_validate;;
usage|help) agent_usage
exit $OCF_SUCCESS
;;
*) agent_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/HealthSMART.in b/extra/resources/HealthSMART.in
index 172b508937..7889a8f8a4 100755
--- a/extra/resources/HealthSMART.in
+++ b/extra/resources/HealthSMART.in
@@ -1,317 +1,317 @@
#!@BASH_PATH@
#
# ocf:pacemaker:HealthSMART resource agent
#
# Copyright 2009-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#
# Checks the S.M.A.R.T. status of all given drives and writes the #health-smart
# status into the CIB
#
#######################################################################
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS:="${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"}
. "${OCF_FUNCTIONS}"
: ${__OCF_ACTION:="$1"}
#
SMARTCTL=/usr/sbin/smartctl
ATTRDUP=/usr/sbin/attrd_updater
#######################################################################
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="HealthSMART" version="0.1">
<version>1.0</version>
<longdesc lang="en">
Systhem health agent that checks the S.M.A.R.T. status of the given drives and
updates the #health-smart attribute.
</longdesc>
<shortdesc lang="en">SMART health status</shortdesc>
<parameters>
<parameter name="state" unique="1">
<longdesc lang="en">
Location to store the resource state in.
</longdesc>
<shortdesc lang="en">State file</shortdesc>
<content type="string" default="${HA_VARRUN%%/}/HealthSMART-${OCF_RESOURCE_INSTANCE}.state" />
</parameter>
<parameter name="drives" unique="0">
<longdesc lang="en">
The drive(s) to check as a SPACE separated list. Enter the full path to the device, e.g. "/dev/sda".
</longdesc>
<shortdesc lang="en">Drives to check</shortdesc>
<content type="string" default="/dev/sda" />
</parameter>
<parameter name="devices" unique="0">
<longdesc lang="en">
The device type(s) to assume for the drive(s) being tested as a SPACE separated list.
</longdesc>
<shortdesc lang="en">Device types</shortdesc>
<content type="string" />
</parameter>
<parameter name="temp_lower_limit" unique="0">
<longdesc lang="en">
Lower limit of the temperature in deg C of the drive(s). Below this limit the status will be red.
</longdesc>
<shortdesc lang="en">Lower limit for the red smart attribute</shortdesc>
<content type="string" default="0"/>
</parameter>
<parameter name="temp_upper_limit" unique="0">
<longdesc lang="en">
Upper limit of the temperature if deg C of the drives(s). If the drive reports
a temperature higher than this value the status of #health-smart will be red.
</longdesc>
<shortdesc lang="en">Upper limit for red smart attribute</shortdesc>
<content type="string" default="60"/>
</parameter>
<parameter name="temp_warning" unique="0">
<longdesc lang="en">
Number of deg C below/above the upper/lower temp limits at which point the status of #health-smart will change to yellow.
</longdesc>
<shortdesc lang="en">Deg C below/above the upper limits for yellow smart attribute</shortdesc>
<content type="string" default="5"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="10s" />
<action name="stop" timeout="10s" />
<action name="monitor" timeout="10s" interval="10s" start-delay="0s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="10s" />
</actions>
</resource-agent>
END
}
#######################################################################
check_temperature() {
if [ $1 -lt ${lower_red_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} too cold: ${1} C"
"$ATTRDUP" -n "#health-smart" -U "red" -d "5s"
return 1
fi
if [ $1 -gt ${upper_red_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} too hot: ${1} C"
"$ATTRDUP" -n "#health-smart" -U "red" -d "5s"
return 1
fi
if [ $1 -lt ${lower_yellow_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} quite cold: ${1} C"
"$ATTRDUP" -n "#health-smart" -U "yellow" -d "5s"
return 1
fi
if [ $1 -gt ${upper_yellow_limit} ] ; then
ocf_log info "Drive ${DRIVE} ${DEVICE} quite hot: ${1} C"
"$ATTRDUP" -n "#health-smart" -U "yellow" -d "5s"
return 1
fi
}
init_smart() {
#Set temperature defaults
if [ -z "${OCF_RESKEY_temp_warning}" ]; then
yellow_threshold=5
else
yellow_threshold=${OCF_RESKEY_temp_warning}
fi
if [ -z "${OCF_RESKEY_temp_lower_limit}" ] ; then
lower_red_limit=0
else
lower_red_limit=${OCF_RESKEY_temp_lower_limit}
fi
lower_yellow_limit=$((${lower_red_limit}+${yellow_threshold}))
if [ -z "${OCF_RESKEY_temp_upper_limit}" ] ; then
upper_red_limit=60
else
upper_red_limit=${OCF_RESKEY_temp_upper_limit}
fi
upper_yellow_limit=$((${upper_red_limit}-${yellow_threshold}))
#Set disk defaults
if [ -z "${OCF_RESKEY_drives}" ] ; then
DRIVES="/dev/sda"
else
DRIVES=${OCF_RESKEY_drives}
fi
#Test for presence of smartctl
if [ ! -x "$SMARTCTL" ] ; then
ocf_log err "${SMARTCTL} not installed."
exit $OCF_ERR_INSTALLED
fi
for DRIVE in $DRIVES; do
- if [ "${OCF_RESKEY_devices}" ]; then
+ if [ -n "${OCF_RESKEY_devices}" ]; then
for DEVICE in ${OCF_RESKEY_devices}; do
"$SMARTCTL" -d "$DEVICE" -i "${DRIVE}" | grep -q "SMART support is: Enabled"
if [ $? -ne 0 ] ; then
ocf_log err "S.M.A.R.T. not enabled for drive "${DRIVE}
exit $OCF_ERR_INSTALLED
fi
done
else
"$SMARTCTL" -i "${DRIVE}" | grep -q "SMART support is: Enabled"
if [ $? -ne 0 ] ; then
ocf_log err "S.M.A.R.T. not enabled for drive "${DRIVE}
exit $OCF_ERR_INSTALLED
fi
fi
done
}
HealthSMART_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
HealthSMART_start() {
HealthSMART_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
touch "${OCF_RESKEY_state}"
}
HealthSMART_stop() {
HealthSMART_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
rm "${OCF_RESKEY_state}"
fi
return $OCF_SUCCESS
}
HealthSMART_monitor() {
init_smart
# Monitor _MUST!_ differentiate correctly between running
# (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING).
# That is THREE states, not just yes/no.
if [ -f "${OCF_RESKEY_state}" ]; then
# Check overall S.M.A.R.T. status
for DRIVE in $DRIVES; do
- if [ "${OCF_RESKEY_devices}" ]; then
+ if [ -n "${OCF_RESKEY_devices}" ]; then
for DEVICE in ${OCF_RESKEY_devices}; do
"$SMARTCTL" -d "$DEVICE" -H ${DRIVE} | grep -q "SMART overall-health self-assessment test result: PASSED"
if [ $? -ne 0 ]; then
"$ATTRDUP" -n "#health-smart" -U "red" -d "5s"
return $OCF_SUCCESS
fi
done
else
"$SMARTCTL" -H "${DRIVE}" | grep -q "SMART overall-health self-assessment test result: PASSED"
if [ $? -ne 0 ]; then
"$ATTRDUP" -n "#health-smart" -U "red" -d "5s"
return $OCF_SUCCESS
fi
fi
# Check drive temperature(s)
- if [ "${OCF_RESKEY_devices}" ]; then
+ if [ -n "${OCF_RESKEY_devices}" ]; then
for DEVICE in ${OCF_RESKEY_devices}; do
check_temperature "$("$SMARTCTL" -d "$DEVICE" -A "${DRIVE}" | awk '/^194/ { print $10 }')"
if [ $? -ne 0 ]; then
return $OCF_SUCCESS
fi
done
else
check_temperature "$("$SMARTCTL" -A "${DRIVE}" | awk '/^194/ { print $10 }')"
if [ $? -ne 0 ]; then
return $OCF_SUCCESS
fi
fi
done
"$ATTRDUP" -n "#health-smart" -U "green" -d "5s"
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
HealthSMART_validate() {
init_smart
# Is the state directory writable?
state_dir=$(dirname "$OCF_RESKEY_state")
touch "$state_dir/$$"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
return $OCF_ERR_ARGS
fi
rm "$state_dir/$$"
return $OCF_SUCCESS
}
: ${OCF_RESKEY_CRM_meta_interval:=0}
: ${OCF_RESKEY_CRM_meta_globally_unique:="true"}
-if [ "x$OCF_RESKEY_state" = "x" ]; then
+if [ -z "$OCF_RESKEY_state" ]; then
if [ "${OCF_RESKEY_CRM_meta_globally_unique}" = "false" ]; then
state="${HA_VARRUN%%/}/HealthSMART-${OCF_RESOURCE_INSTANCE}.state"
# Strip off the trailing clone marker
OCF_RESKEY_state=$(echo $state | sed s/:[0-9][0-9]*\.state/.state/)
else
OCF_RESKEY_state="${HA_VARRUN%%/}/HealthSMART-${OCF_RESOURCE_INSTANCE}.state"
fi
fi
case "$__OCF_ACTION" in
start) HealthSMART_start;;
stop) HealthSMART_stop;;
monitor) HealthSMART_monitor;;
validate-all) HealthSMART_validate;;
meta-data)
meta_data
exit $OCF_SUCCESS
;;
usage|help)
HealthSMART_usage
exit $OCF_SUCCESS
;;
*) HealthSMART_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/Stateful b/extra/resources/Stateful
index 207a5b5974..8e732df5fd 100755
--- a/extra/resources/Stateful
+++ b/extra/resources/Stateful
@@ -1,243 +1,243 @@
#!/bin/sh
#
# ocf:pacemaker:Stateful resource agent
#
# Copyright 2006-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
#
# Example of a stateful OCF Resource Agent
#
#######################################################################
# 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="Stateful" version="1.1">
<version>1.0</version>
<longdesc lang="en">
This is an example resource agent that implements two states
</longdesc>
<shortdesc lang="en">Example stateful resource agent</shortdesc>
<parameters>
<parameter name="state" unique="1">
<longdesc lang="en">
Location to store the resource state in
</longdesc>
<shortdesc lang="en">State file</shortdesc>
<content type="string" default="${HA_VARRUN%%/}/Stateful-${OCF_RESOURCE_INSTANCE}.state" />
</parameter>
<parameter name="envfile" unique="1">
<longdesc lang="en">
If this is set, the environment will be dumped to this file for every call.
</longdesc>
<shortdesc lang="en">Environment dump file</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="notify_delay" unique="0">
<longdesc lang="en">
The notify action will sleep for this many seconds before returning,
to simulate a long-running notify.
</longdesc>
<shortdesc lang="en">Notify delay in seconds</shortdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="20s" interval="10s" role="Master"/>
<action name="monitor" depth="0" timeout="20s" interval="10s" role="Slave"/>
<action name="notify" timeout="5s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
#######################################################################
stateful_usage() {
cat <<END
usage: $0 {start|stop|promote|demote|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
exit $1
}
stateful_update() {
echo $1 > "${OCF_RESKEY_state}"
}
stateful_check_state() {
target="$1"
if [ -f "${OCF_RESKEY_state}" ]; then
state=$(cat "${OCF_RESKEY_state}")
- if [ "x$target" = "x$state" ]; then
+ if [ "$target" = "$state" ]; then
return 0
fi
else
- if [ "x$target" = "x" ]; then
+ if [ -z "$target" ]; then
return 0
fi
fi
return 1
}
dump_env() {
if [ "${OCF_RESKEY_envfile}" != "" ]; then
echo "### ${__OCF_ACTION} @ $(date) ###
$(env | sort)
###" >> "${OCF_RESKEY_envfile}"
fi
}
set_master_score() {
"${HA_SBIN_DIR}/crm_master" -l reboot -v "$1"
}
stateful_start() {
stateful_check_state master
- if [ $? = 0 ]; then
+ if [ $? -eq 0 ]; then
# CRM Error - Should never happen
return $OCF_RUNNING_MASTER
fi
stateful_update slave
set_master_score "${slave_score}"
return 0
}
stateful_demote() {
stateful_check_state
- if [ $? = 0 ]; then
+ if [ $? -eq 0 ]; then
# CRM Error - Should never happen
return $OCF_NOT_RUNNING
fi
stateful_update slave
set_master_score "${slave_score}"
return 0
}
stateful_promote() {
stateful_check_state
- if [ $? = 0 ]; then
+ if [ $? -eq 0 ]; then
return $OCF_NOT_RUNNING
fi
stateful_update master
set_master_score "${master_score}"
return 0
}
stateful_stop() {
"${HA_SBIN_DIR}/crm_master" -l reboot -D
stateful_check_state master
- if [ $? = 0 ]; then
+ if [ $? -eq 0 ]; then
# CRM Error - Should never happen
return $OCF_RUNNING_MASTER
fi
if [ -f "${OCF_RESKEY_state}" ]; then
rm "${OCF_RESKEY_state}"
fi
return 0
}
stateful_monitor() {
stateful_check_state "master"
- if [ $? = 0 ]; then
- if [ $OCF_RESKEY_CRM_meta_interval = 0 ]; then
+ if [ $? -eq 0 ]; then
+ if [ $OCF_RESKEY_CRM_meta_interval -eq 0 ]; then
# Restore the master setting during probes
set_master_score "${master_score}"
fi
return $OCF_RUNNING_MASTER
fi
stateful_check_state "slave"
- if [ $? = 0 ]; then
- if [ $OCF_RESKEY_CRM_meta_interval = 0 ]; then
+ if [ $? -eq 0 ]; then
+ if [ $OCF_RESKEY_CRM_meta_interval -eq 0 ]; then
# Restore the master setting during probes
set_master_score "${slave_score}"
fi
return $OCF_SUCCESS
fi
if [ -f "${OCF_RESKEY_state}" ]; then
echo "File '${OCF_RESKEY_state}' exists but contains unexpected contents"
cat "${OCF_RESKEY_state}"
return $OCF_ERR_GENERIC
fi
return 7
}
stateful_notify() {
if [ "${OCF_RESKEY_notify_delay}" != "0" ]; then
sleep "${OCF_RESKEY_notify_delay}"
fi
return $OCF_SUCCESS
}
stateful_validate() {
exit $OCF_SUCCESS
}
: ${slave_score:=5}
: ${master_score:=10}
: ${OCF_RESKEY_CRM_meta_interval:=0}
: ${OCF_RESKEY_notify_delay:=0}
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
-if [ "x$OCF_RESKEY_state" = "x" ]; then
+if [ -z "$OCF_RESKEY_state" ]; then
if [ "${OCF_RESKEY_CRM_meta_globally_unique}" = "false" ]; then
state="${HA_VARRUN%%/}/Stateful-${OCF_RESOURCE_INSTANCE}.state"
# Strip off the trailing clone marker
OCF_RESKEY_state=$(echo $state | sed s/:[0-9][0-9]*\.state/.state/)
else
OCF_RESKEY_state="${HA_VARRUN%%/}/Stateful-${OCF_RESOURCE_INSTANCE}.state"
fi
fi
dump_env
case "$__OCF_ACTION" in
meta-data) meta_data;;
start) stateful_start;;
promote) stateful_promote;;
demote) stateful_demote;;
notify) stateful_notify ;;
stop) stateful_stop;;
monitor) stateful_monitor;;
validate-all) stateful_validate;;
usage|help) stateful_usage $OCF_SUCCESS;;
*) stateful_usage $OCF_ERR_UNIMPLEMENTED;;
esac
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/SysInfo.in b/extra/resources/SysInfo.in
index 828311e7ca..fa535beeee 100755
--- a/extra/resources/SysInfo.in
+++ b/extra/resources/SysInfo.in
@@ -1,372 +1,372 @@
#!@BASH_PATH@
#
# ocf:pacemaker:SysInfo resource agent
#
# Original copyright 2004 SUSE LINUX AG, Lars Marowsky-Br<E9>e
# Later changes copyright 2008-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#
# This agent records (in the CIB) various attributes of a node
#
#######################################################################
# 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="SysInfo" version="1.0">
<version>1.0</version>
<longdesc lang="en">
This is a SysInfo Resource Agent.
It records (in the CIB) various attributes of a node
Sample Linux output:
arch: i686
os: Linux-2.4.26-gentoo-r14
free_swap: 1999
cpu_info: Intel(R) Celeron(R) CPU 2.40GHz
cpu_speed: 4771.02
cpu_cores: 1
cpu_load: 0.00
ram_total: 513
ram_free: 117
root_free: 2.4
#health_disk: red
Sample Darwin output:
arch: i386
os: Darwin-8.6.2
cpu_info: Intel Core Duo
cpu_speed: 2.16
cpu_cores: 2
cpu_load: 0.18
ram_total: 2016
ram_free: 787
root_free: 13
#health_disk: green
Units:
free_swap: MB
ram_*: MB
cpu_speed (Linux): bogomips
cpu_speed (Darwin): GHz
*_free: GB (or user-defined: disk_unit)
</longdesc>
<shortdesc lang="en">SysInfo resource agent</shortdesc>
<parameters>
<parameter name="pidfile" unique="1">
<longdesc lang="en">PID file</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="$OCF_RESKEY_pidfile" />
</parameter>
<parameter name="delay" unique="0">
<longdesc lang="en">Interval to allow values to stabilize</longdesc>
<shortdesc lang="en">Dampening Delay</shortdesc>
<content type="string" default="0s" />
</parameter>
<parameter name="disks" unique="0">
<longdesc lang="en">
Filesystems or Paths to be queried for free disk space as a SPACE
separated list - e.g "/dev/sda1 /tmp".
Results will be written to an attribute with leading slashes
removed, and other slashes replaced with underscore, and the word
'free' appended - e.g for /dev/sda1 it would be 'dev_sda1_free'.
Note: The root filesystem '/' is always queried to an attribute
named 'root_free'
</longdesc>
<shortdesc lang="en">List of Filesytems/Paths to query for free disk space</shortdesc>
<content type="string" />
</parameter>
<parameter name="disk_unit" unique="0">
<longdesc lang="en">
Unit to report disk free space in.
Can be one of: B, K, M, G, T, P (case-insensitive)
</longdesc>
<shortdesc lang="en">Unit to report disk free space in</shortdesc>
<content type="string" default="G"/>
</parameter>
<parameter name="min_disk_free" unique="0">
<longdesc lang="en">
The amount of free space required in monitored disks. If any
of the monitored disks has less than this amount of free space,
, with the node attribute "#health_disk" changing to "red",
all resources will move away from the node. Set the node-health-strategy
property appropriately for this to take effect.
If the unit is not specified, it defaults to disk_unit.
</longdesc>
<shortdesc lang="en">minimum disk free space required</shortdesc>
<content type="string" default=""/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" timeout="20s" interval="60s"/>
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
}
#######################################################################
UpdateStat() {
name="$1"; shift
value="$*"
printf "%s:\t%s\n" "$name" "$value"
if [ "$__OCF_ACTION" = "start" ] ; then
"${HA_SBIN_DIR}/attrd_updater" ${OCF_RESKEY_delay} -S status -n $name -B "$value"
else
"${HA_SBIN_DIR}/attrd_updater" ${OCF_RESKEY_delay} -S status -n $name -v "$value"
fi
}
SysInfoStats() {
UpdateStat arch "$(uname -m)"
UpdateStat os "$(uname -s)-$(uname -r)"
case $(uname -s) in
"Darwin")
mem=$(top -l 1 | grep Mem: | awk '{print $10}')
mem_used=$(top -l 1 | grep Mem: | awk '{print $8}')
mem=$(SysInfo_mem_units "$mem")
mem_used=$(SysInfo_mem_units "$mem_used")
mem_total=$(expr $mem_used + $mem)
cpu_type=$(system_profiler SPHardwareDataType | awk -F': ' '/^CPU Type/ {print $2; exit}')
cpu_speed=$(system_profiler SPHardwareDataType | awk -F': ' '/^CPU Speed/ {print $2; exit}')
cpu_cores=$(system_profiler SPHardwareDataType | awk -F': ' '/^Number Of/ {print $2; exit}')
cpu_load=$(uptime | awk '{ print $10 }')
;;
"FreeBSD")
cpu_type=$(sysctl -in hw.model)
cpu_speed=$(sysctl -in dev.cpu.0.freq)
cpu_cores=$(sysctl -in hw.ncpu)
cpu_load=$(sysctl -in vm.loadavg | awk '{ print $4 }')
free_pages=$(sysctl -in vm.stats.vm.v_free_count)
page_count=$(sysctl -in vm.stats.vm.v_page_count)
page_size=$(sysctl -in vm.stats.vm.v_page_size)
mem=$(expr $free_pages \* $page_size / 1024 / 1024)M
mem_total=$(expr $page_count \* $page_size / 1024 / 1024)M
;;
"Linux")
if [ -f /proc/cpuinfo ]; then
cpu_type=$(awk -F': ' '/model name/ {print $2; exit}' /proc/cpuinfo)
cpu_speed=$(awk -F': ' '/bogomips/ {print $2; exit}' /proc/cpuinfo)
cpu_cores=$(grep "^processor" /proc/cpuinfo | wc -l)
fi
cpu_load=$(uptime | awk '{ print $10 }')
if [ -f /proc/meminfo ]; then
# meminfo results are in kB
mem=$(grep "SwapFree" /proc/meminfo | awk '{print $2"k"}')
- if [ ! -z "$mem" ]; then
+ if [ -n "$mem" ]; then
UpdateStat free_swap "$(SysInfo_mem_units "$mem")"
fi
mem=$(grep "Inactive" /proc/meminfo | awk '{print $2"k"}')
mem_total=$(grep "MemTotal" /proc/meminfo | awk '{print $2"k"}')
else
mem=$(top -n 1 | grep Mem: | awk '{print $7}')
fi
;;
*)
esac
- if [ x != x"$cpu_type" ]; then
+ if [ -n "$cpu_type" ]; then
UpdateStat cpu_info "$cpu_type"
fi
- if [ x != x"$cpu_speed" ]; then
+ if [ -n "$cpu_speed" ]; then
UpdateStat cpu_speed "$cpu_speed"
fi
- if [ x != x"$cpu_cores" ]; then
+ if [ -n "$cpu_cores" ]; then
UpdateStat cpu_cores "$cpu_cores"
fi
- if [ x != x"$cpu_load" ]; then
+ if [ -n "$cpu_load" ]; then
UpdateStat cpu_load "$cpu_load"
fi
- if [ ! -z "$mem" ]; then
+ if [ -n "$mem" ]; then
# Massage the memory values
UpdateStat ram_total "$(SysInfo_mem_units "$mem_total")"
UpdateStat ram_free "$(SysInfo_mem_units "$mem")"
fi
# Portability notes:
# o tail: explicit "-n" not available in Solaris; instead simplify
# 'tail -n <c>' to the equivalent 'tail -<c>'.
for disk in "/" ${OCF_RESKEY_disks}; do
unset disk_free disk_label
disk_free=$(df -h "${disk}" | tail -1 | awk '{print $4}')
- if [ x != x"$disk_free" ]; then
+ if [ -n "$disk_free" ]; then
disk_label=$(echo $disk | sed -e 's#^/$#root#;s#^/*##;s#/#_#g')
disk_free=$(SysInfo_hdd_units "$disk_free")
UpdateStat "${disk_label}_free" $disk_free
if [ -n "$MIN_FREE" ]; then
if [ $disk_free -le $MIN_FREE ]; then
UpdateStat "#health_disk" "red"
else
UpdateStat "#health_disk" "green"
fi
fi
fi
done
}
SysInfo_megabytes() {
# Size in megabytes
echo $1 | awk '{ n = $0;
sub(/[0-9]+(.[0-9]+)?/, "");
split(n, a, $0);
n=a[1];
if ($0 == "G" || $0 == "") { n *= 1024 };
if (/^kB?/) { n /= 1024 };
printf "%d\n", n }' # Intentionally round to an integer
}
SysInfo_mem_units() {
mem="$1"
if [ -z "$1" ]; then
return
fi
mem=$(SysInfo_megabytes "$1")
# Round to the next multiple of 50
r=$(($mem % 50))
- if [ $r != 0 ]; then
+ if [ $r -ne 0 ]; then
mem=$(($mem + 50 - $r))
fi
echo $mem
}
SysInfo_hdd_units() {
# Defauts to size in gigabytes
case "$OCF_RESKEY_disk_unit" in
[Pp]) echo $(($(SysInfo_megabytes "$1") / 1024 / 1024 / 1024));;
[Tt]) echo $(($(SysInfo_megabytes "$1") / 1024 / 1024));;
[Gg]) echo $(($(SysInfo_megabytes "$1") / 1024));;
[Mm]) echo "$(SysInfo_megabytes "$1")" ;;
[Kk]) echo $(($(SysInfo_megabytes "$1") * 1024));;
[Bb]) echo $(($(SysInfo_megabytes "$1") * 1024 * 1024));;
*)
ocf_log err "Invalid value for disk_unit: $OCF_RESKEY_disk_unit"
echo $(($(SysInfo_megabytes "$1") / 1024));;
esac
}
SysInfo_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
SysInfo_start() {
echo $OCF_RESKEY_clone > "$OCF_RESKEY_pidfile"
SysInfoStats
exit $OCF_SUCCESS
}
SysInfo_stop() {
rm "$OCF_RESKEY_pidfile"
exit $OCF_SUCCESS
}
SysInfo_monitor() {
if [ -f "$OCF_RESKEY_pidfile" ]; then
clone=$(cat "$OCF_RESKEY_pidfile")
fi
- if [ "x$clone" = "x" ]; then
+ if [ -z "$clone" ]; then
rm "$OCF_RESKEY_pidfile"
exit $OCF_NOT_RUNNING
elif [ "$clone" = "$OCF_RESKEY_clone" ]; then
SysInfoStats
exit $OCF_SUCCESS
elif ocf_is_true "$OCF_RESKEY_CRM_meta_globally_unique"; then
SysInfoStats
exit $OCF_SUCCESS
fi
exit $OCF_NOT_RUNNING
}
SysInfo_validate() {
return $OCF_SUCCESS
}
if [ $# -ne 1 ]; then
SysInfo_usage
exit $OCF_ERR_ARGS
fi
: ${OCF_RESKEY_pidfile:="${HA_VARRUN%%/}/SysInfo-${OCF_RESOURCE_INSTANCE}"}
: ${OCF_RESKEY_disk_unit:="G"}
: ${OCF_RESKEY_clone:="0"}
-if [ "x" != "x${OCF_RESKEY_delay}" ]; then
+if [ -n "${OCF_RESKEY_delay}" ]; then
OCF_RESKEY_delay="-d ${OCF_RESKEY_delay}"
else
OCF_RESKEY_delay="-d 0"
fi
MIN_FREE=""
if [ -n "$OCF_RESKEY_min_disk_free" ]; then
ocf_is_decimal "$OCF_RESKEY_min_disk_free" &&
OCF_RESKEY_min_disk_free="$OCF_RESKEY_min_disk_free$OCF_RESKEY_disk_unit"
MIN_FREE=$(SysInfo_hdd_units $OCF_RESKEY_min_disk_free)
fi
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) SysInfo_start
;;
stop) SysInfo_stop
;;
monitor) SysInfo_monitor
;;
validate-all) SysInfo_validate
;;
usage|help) SysInfo_usage
exit $OCF_SUCCESS
;;
*) SysInfo_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/SystemHealth b/extra/resources/SystemHealth
index a05d97d803..480fa79c10 100755
--- a/extra/resources/SystemHealth
+++ b/extra/resources/SystemHealth
@@ -1,239 +1,239 @@
#!/bin/sh
#
# ocf:pacemaker:SystemHealth resource agent
#
# Copyright 2009-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#######################################################################
# 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="SystemHealth" version="0.1">
<version>1.0</version>
<longdesc lang="en">
This is a SystemHealth Resource Agent. It is used to monitor
the health of a system via IPMI.
</longdesc>
<shortdesc lang="en">SystemHealth resource agent</shortdesc>
<parameters>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" timeout="20s" />
<action name="reload" timeout="20s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="20s" />
</actions>
</resource-agent>
END
}
#######################################################################
SystemHealth_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
SystemHealth_check_tools() {
which servicelog_notify > /dev/null 2>&1
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "servicelog_notify not found!"
return $OCF_ERR_INSTALLED
fi
which ipmiservicelogd > /dev/null 2>&1
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "ipmiservicelogd not found!"
return $OCF_ERR_INSTALLED
fi
test -x "$OCF_RESKEY_program"
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "$OCF_RESKEY_program not found!"
return $OCF_ERR_INSTALLED
fi
}
SystemHealth_start() {
SystemHealth_monitor
RC=$?
- if [ $RC = $OCF_ERR_GENERIC ]; then
+ if [ $RC -eq $OCF_ERR_GENERIC ]; then
return $OCF_ERR_GENERIC
- elif [ $RC = $OCF_SUCCESS ]; then
+ elif [ $RC -eq $OCF_SUCCESS ]; then
ocf_log warn "starting an already started SystemHealth"
return $OCF_SUCCESS
fi
service ipmi start > /dev/null 2>&1
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "Could not start service IPMI!"
return $OCF_ERR_GENERIC
fi
ipmiservicelogd smi 0 > /dev/null 2>&1 &
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "Could not start ipmiservicelogd!"
return $OCF_ERR_GENERIC
fi
servicelog_notify --add --type=EVENT --command="$OCF_RESKEY_program" --method=num_arg --match='type=4' > /dev/null 2>&1
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log err "servicelog_notify register handler failed!"
return $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
}
SystemHealth_stop() {
SystemHealth_monitor
RC=$?
- if [ $RC = $OCF_ERR_GENERIC ]; then
+ if [ $RC -eq $OCF_ERR_GENERIC ]; then
return $OCF_ERR_GENERIC
- elif [ $RC = $OCF_SUCCESS ]; then
+ elif [ $RC -eq $OCF_SUCCESS ]; then
killall ipmiservicelogd
RC1=$?
- if [ $RC1 != 0 ]; then
+ if [ $RC1 -ne 0 ]; then
ocf_log err "Could not stop ipmiservicelogd!"
fi
servicelog_notify --remove --command="$OCF_RESKEY_program" > /dev/null 2>&1
RC2=$?
- if [ $RC2 != 0 ]; then
+ if [ $RC2 -ne 0 ]; then
ocf_log err "servicelog_notify remove handler failed!"
fi
if [ $RC1 -eq 0 ] && [ $RC2 -eq 0 ]; then
return $OCF_SUCCESS
else
return $OCF_ERR_GENERIC
fi
- elif [ $RC = $OCF_NOT_RUNNING ]; then
+ elif [ $RC -eq $OCF_NOT_RUNNING ]; then
ocf_log warn "stopping an already stopped SystemHealth"
return $OCF_SUCCESS
else
ocf_log err "SystemHealth_stop: should not be here!"
return $OCF_ERR_GENERIC
fi
}
SystemHealth_monitor() {
# Monitor _MUST!_ differentiate correctly between running
# (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING).
# That is THREE states, not just yes/no.
if [ ! -f /var/run/ipmiservicelogd.pid0 ]; then
ocf_log debug "ipmiservicelogd is not running!"
return $OCF_NOT_RUNNING
fi
ps -p "$(cat /var/run/ipmiservicelogd.pid0)" >/dev/null 2>&1
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
ocf_log debug "ipmiservicelogd's pid $(cat /var/run/ipmiservicelogd.pid0) is not running!"
rm /var/run/ipmiservicelogd.pid0
return $OCF_ERR_GENERIC
fi
servicelog_notify --list --command="$OCF_RESKEY_program" > /dev/null 2>&1
RC=$?
- if [ $RC = 0 ]; then
+ if [ $RC -eq 0 ]; then
return $OCF_SUCCESS
else
return $OCF_NOT_RUNNING
fi
}
SystemHealth_validate() {
SystemHealth_check_tools
RC=$?
- if [ $RC != 0 ]; then
+ if [ $RC -ne 0 ]; then
return $RC
fi
return $OCF_SUCCESS
}
: ${OCF_RESKEY_program:=/usr/sbin/notifyServicelogEvent}
case $__OCF_ACTION in
meta-data) meta_data
exit $OCF_SUCCESS
;;
usage|help) SystemHealth_usage
exit $OCF_SUCCESS
;;
esac
SystemHealth_check_tools
RC=$?
-if [ $RC != 0 ]; then
+if [ $RC -ne 0 ]; then
case "$__OCF_ACTION" in
stop) exit $OCF_SUCCESS;;
*) exit $RC;;
esac
fi
case "$__OCF_ACTION" in
start) SystemHealth_start;;
stop) SystemHealth_stop;;
monitor) SystemHealth_monitor;;
reload) ocf_log info "Reloading..."
SystemHealth_start
;;
validate-all) ;;
*) SystemHealth_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/controld b/extra/resources/controld
index 147aaa4ab1..7cc6a6ff33 100755
--- a/extra/resources/controld
+++ b/extra/resources/controld
@@ -1,288 +1,288 @@
#!/bin/sh
#
# ocf:pacemaker:controld resource agent
#
# Copyright 2008-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
# Manages the DLM controld process
#
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS:="${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"}
. "${OCF_FUNCTIONS}"
: ${__OCF_ACTION:="$1"}
#######################################################################
if [ -e "$OCF_ROOT/resource.d/heartbeat/controld" ]; then
ocf_log info "Using heartbeat controld agent"
"$OCF_ROOT/resource.d/heartbeat/controld" "$1"
exit $?
fi
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="controld" version="1.1">
<version>1.0</version>
<longdesc lang="en">
This Resource Agent can control the dlm_controld services needed by cluster-aware file systems.
It assumes that dlm_controld is in your default PATH.
In most cases, it should be run as an anonymous clone.
</longdesc>
<shortdesc lang="en">DLM Agent for cluster file systems</shortdesc>
<parameters>
<parameter name="args" unique="1">
<longdesc lang="en">
Any additional options to start the dlm_controld service with
</longdesc>
<shortdesc lang="en">DLM Options</shortdesc>
<content type="string" default="-s 0" />
</parameter>
<parameter name="daemon" unique="1">
<longdesc lang="en">
The daemon to start - supports gfs_controld and dlm_controld
</longdesc>
<shortdesc lang="en">The daemon to start</shortdesc>
<content type="string" default="dlm_controld" />
</parameter>
<parameter name="allow_stonith_disabled">
<longdesc lang="en">
Allow DLM start-up even if STONITH/fencing is disabled in the cluster.
Setting this option to true will cause cluster malfunction and hangs on
fail-over for DLM clients that require fencing (such as GFS2, OCFS2, and
cLVM2).
This option is advanced use only.
</longdesc>
<shortdesc lang="en">Allow start-up even without STONITH/fencing</shortdesc>
<content type="string" default="false" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="90s" />
<action name="stop" timeout="100s" />
<action name="monitor" timeout="20s" interval="10s" depth="0" start-delay="0s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
}
#######################################################################
CONFIGFS_DIR="/sys/kernel/config"
DLM_CONFIGFS_DIR="${CONFIGFS_DIR}/dlm"
DLM_SYSFS_DIR="/sys/kernel/dlm"
controld_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
check_uncontrolled_locks()
{
CUL_TMP=$(ls "$DLM_SYSFS_DIR" 2>&1)
if [ $? -eq 0 ]; then
if [ -n "$CUL_TMP" ]; then
ocf_log err "Uncontrolled lockspace exists, system must reboot. Executing suicide fencing"
stonith_admin --reboot="$(crm_node -n)" --tag controld
exit $OCF_ERR_GENERIC
fi
fi
}
controld_start() {
controld_monitor; rc=$?
case $rc in
$OCF_SUCCESS) return $OCF_SUCCESS;;
$OCF_NOT_RUNNING) ;;
*) return $OCF_ERR_GENERIC;;
esac
# Ensure configfs is mounted
if [ ! -e "$CONFIGFS_DIR" ]; then
modprobe configfs
if [ ! -e "$CONFIGFS_DIR" ]; then
ocf_log err "$CONFIGFS_DIR not available"
return $OCF_ERR_INSTALLED
fi
fi
mount -t configfs | grep " $CONFIGFS_DIR " >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
mount -t configfs none "$CONFIGFS_DIR"
fi
# Ensure DLM is available
if [ ! -e "$DLM_CONFIGFS_DIR" ]; then
modprobe dlm
if [ ! -e "$DLM_CONFIGFS_DIR" ]; then
ocf_log err "$DLM_CONFIGFS_DIR not available"
return $OCF_ERR_INSTALLED
fi
fi
if ! ocf_is_true "$OCF_RESKEY_allow_stonith_disabled" && \
! ocf_is_true "$(crm_attribute --type=crm_config --name=stonith-enabled --query --quiet --default=true)"; then
ocf_log err "The cluster property stonith-enabled may not be deactivated to use the DLM"
return $OCF_ERR_CONFIGURED
fi
"${OCF_RESKEY_daemon}" $OCF_RESKEY_args
while true
do
sleep 1
controld_monitor; rc=$?
case $rc in
$OCF_SUCCESS)
CS_ADDR_LIST="$(cat "${DLM_CONFIGFS_DIR}"/cluster/comms/*/addr_list 2>/dev/null)"
if [ $? -eq 0 ] && [ -n "$CS_ADDR_LIST" ]; then
return $OCF_SUCCESS
fi
;;
$OCF_NOT_RUNNING)
return $OCF_NOT_RUNNING
;;
*)
return $OCF_ERR_GENERIC
;;
esac
ocf_log debug "Waiting for ${OCF_RESKEY_daemon} to be ready"
done
}
controld_stop() {
controld_monitor; rc=$?
- if [ $rc = $OCF_NOT_RUNNING ]; then
+ if [ $rc -eq $OCF_NOT_RUNNING ]; then
return $OCF_SUCCESS
fi
killall -TERM "${OCF_RESKEY_daemon}"; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
return $OCF_ERR_GENERIC
fi
rc=$OCF_SUCCESS
- while [ $rc = $OCF_SUCCESS ]; do
+ while [ $rc -eq $OCF_SUCCESS ]; do
controld_monitor; rc=$?
sleep 1
done
- if [ $rc = $OCF_NOT_RUNNING ]; then
+ if [ $rc -eq $OCF_NOT_RUNNING ]; then
rc=$OCF_SUCCESS
fi
return $rc
}
controld_monitor() {
killall -0 ${OCF_RESKEY_daemon} >/dev/null 2>&1 ; CM_RC=$?
case $CM_RC in
0) smw=$(dlm_tool status -v | grep "stateful_merge_wait=" | cut -d= -f2)
if [ -n "$smw" ] && [ $smw -eq 1 ]; then
ocf_log err "DLM status is: stateful_merge_wait"
CM_RC=$OCF_ERR_GENERIC
elif [ -z "$smw" ] && dlm_tool ls | grep -q "wait fencing" && \
! stonith_admin -H '*' -V | grep -q "wishes to"; then
ocf_log err "DLM status is: wait fencing"
CM_RC=$OCF_ERR_GENERIC
else
CM_RC=$OCF_SUCCESS
fi
;;
1) CM_RC=$OCF_NOT_RUNNING;;
*) CM_RC=$OCF_ERR_GENERIC;;
esac
# if the dlm is not successfully running, but
# dlm lockspace bits are left over, we self must fence.
if [ $CM_RC -ne $OCF_SUCCESS ]; then
check_uncontrolled_locks
fi
return $CM_RC
}
controld_validate() {
check_binary killall
check_binary "${OCF_RESKEY_daemon}"
case "${OCF_RESKEY_CRM_meta_globally_unique}" in
yes|Yes|true|True|1)
ocf_log err "$OCF_RESOURCE_INSTANCE must be configured with the globally_unique=false meta attribute"
exit $OCF_ERR_CONFIGURED
;;
esac
[ -d /var/run/cluster ] || mkdir /var/run/cluster
return $OCF_SUCCESS
}
: ${OCF_RESKEY_sctp:="false"}
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
case "$OCF_RESOURCE_INSTANCE" in
*[gG][fF][sS]*)
: ${OCF_RESKEY_args=-g 0}
: ${OCF_RESKEY_daemon:=gfs_controld}
;;
*[dD][lL][mM]*)
: ${OCF_RESKEY_args=-s 0}
: ${OCF_RESKEY_daemon:=dlm_controld}
;;
*)
: ${OCF_RESKEY_args=-s 0}
: ${OCF_RESKEY_daemon:=dlm_controld}
esac
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) controld_validate; controld_start;;
stop) controld_stop;;
monitor) controld_validate; controld_monitor;;
validate-all) controld_validate;;
usage|help) controld_usage
exit $OCF_SUCCESS
;;
*) controld_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
exit $rc
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/o2cb.in b/extra/resources/o2cb.in
index 5153106673..b5fcf824d6 100755
--- a/extra/resources/o2cb.in
+++ b/extra/resources/o2cb.in
@@ -1,447 +1,447 @@
#!@BASH_PATH@
#
# ocf:pacemaker:o2cb resource agent
#
# Original copyright 2005-2008 Oracle
# Later changes copyright 2008-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#######################################################################
: ${OCF_FUNCTIONS:="${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"}
. "${OCF_FUNCTIONS}"
: ${__OCF_ACTION:="$1"}
: ${OCF_RESKEY_stack:="pcmk"}
: ${OCF_RESKEY_sysfs:="/sys/fs"}
: ${OCF_RESKEY_configfs:="/sys/kernel/config"}
: ${OCF_RESKEY_daemon_timeout:="10"} # How long to wait for things to start
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
DAEMON="/usr/sbin/ocfs2_controld.${OCF_RESKEY_stack}"
CLUSTER_STACK_FILE="${OCF_RESKEY_sysfs}/ocfs2/cluster_stack"
LOADED_PLUGINS_FILE="${OCF_RESKEY_sysfs}/ocfs2/loaded_cluster_plugins"
#
# Check to see if a filesystem driver is loaded.
# 0 is loaded, 1 is not.
#
driver_filesystem() {
if [ -z "$1" ]
then
ocf_log err "driver_filesystem(): Missing an argument"
exit 1
fi
FSNAME="$1"
FSOUT="$(awk '(NF == 1 && $1 ~ /^'$FSNAME'$/) || $2 ~ /^'$FSNAME'$/{
print $1;exit
}' /proc/filesystems 2>/dev/null)"
test -n "$FSOUT"
return $?
}
#
# Check to see if a filesystem of type $1 is mounted at $2.
#
# 0 is mounted, 1 is not.
#
check_filesystem()
{
- if [ $# != 2 -o -z "$1" -o -z "$2" ]
+ if [ $# -ne 2 -o -z "$1" -o -z "$2" ]
then
ocf_log err "check_filesystem(): Missing arguments"
exit 4
fi
FSNAME="$1"
MOUNTPOINT="$2"
FULL_MOUNTSEARCH=$(echo "$MOUNTPOINT" | sed -e 's/\//\\\\\//g')
MOUNTOUT=$(awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/ && $3 ~ /^'$FSNAME'$/{print $2; exit}' < /proc/mounts 2>/dev/null)
test -n "$MOUNTOUT"
return $?
}
#
# Unload a filesystem driver.
# Be careful to notice if the driver is built-in and do nothing.
#
# 0 is success, 1 is error, 2 is already unloaded.
#
unload_filesystem()
{
- if [ $# != 1 -o -z "$1" ]
+ if [ $# -ne 1 -o -z "$1" ]
then
ocf_log err "unload_filesystem(): Missing an argument"
return 1
fi
FSNAME="$1"
driver_filesystem "$FSNAME" || return 2
MODOUT=$(awk '$1 ~ /^'$FSNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null)
if [ -z "$MODOUT" ]; then
# The driver is built in, we can't unload it.
return 0
fi
case "$MODOUT" in
$FSNAME\ 0)
;;
$FSNAME\ *)
# The driver is busy, leave it alone
ocf_log err "Module $FSNAME is still in use"
return 1
;;
*)
ocf_log err "Invalid module parsing! "
return 1
;;
esac
modprobe -rs "$FSNAME"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Unable to unload module: $FSNAME"
return 1
fi
return 0
}
status_daemon()
{
PID=$(pidof "$DAEMON")
if [ -n "$PID" ]; then
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
bringup_daemon()
{
if [ ! -e "$DAEMON" ]; then
ocf_log err "Required binary not found: $DAEMON"
return $OCF_ERR_INSTALLED
fi
"$DAEMON"; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
ocf_log err "Could not start $DAEMON"
return $OCF_ERR_GENERIC
fi
sleep 1
COUNT=0
rc=$OCF_NOT_RUNNING
- while [ $rc = $OCF_NOT_RUNNING ]; do
+ while [ $rc -eq $OCF_NOT_RUNNING ]; do
COUNT=$(expr $COUNT + 1)
if [ $COUNT -gt $OCF_RESKEY_daemon_timeout ]; then
ocf_log err "$(basename $DAEMON) did not come up"
return $OCF_ERR_GENERIC
fi
status_daemon; rc=$?
sleep 1
done
return $rc
}
kill_daemon()
{
status_daemon; rc=$?
- if [ $rc != $OCF_SUCCESS ]; then
+ if [ $rc -ne $OCF_SUCCESS ]; then
return $rc
fi
ocf_log info "Stopping $(basename "$DAEMON")"
killproc "$DAEMON"
- while [ $rc = $OCF_NOT_RUNNING ]; do
+ while [ $rc -eq $OCF_NOT_RUNNING ]; do
sleep 1
status_daemon; rc=$?
done
return $OCF_SUCCESS
}
#
# Unload a module
# 0 is success, 1 is error, 2 is not loaded
#
unload_module()
{
if [ $# -lt 1 -o -z "$1" ]
then
ocf_log err "unload_module(): Requires an argument"
return 1
fi
MODNAME="$1"
MODOUT=$(awk '$1 ~ /^'$MODNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null)
if [ -z "$MODOUT" ]
then
return 2
fi
case "$MODOUT" in
$MODNAME\ 0)
;;
$MODNAME\ *)
return 2
;;
*)
ocf_log err "Invalid module parsing!"
return 1
;;
esac
modprobe -rs "$MODNAME"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Unable to unload module \"$MODNAME\""
return 1
fi
return 0
}
o2cb_start() {
o2cb_monitor; rc=$?
- if [ $rc != $OCF_NOT_RUNNING ]; then
+ if [ $rc -ne $OCF_NOT_RUNNING ]; then
return $rc
fi
ocf_log info "Starting $OCF_RESOURCE_INSTANCE"
if [ ! -e "$CLUSTER_STACK_FILE" ]; then
modprobe -s ocfs2_stackglue
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Could not load ocfs2_stackglue"
return $OCF_ERR_INSTALLED
fi
fi
SP_OUT="$(awk '/^'user'$/{print; exit}' "$LOADED_PLUGINS_FILE" 2>/dev/null)"
if [ -z "$SP_OUT" ]
then
modprobe -s ocfs2_stack_user
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Could not load ocfs2_stack_user"
return $OCF_ERR_INSTALLED
fi
fi
SP_OUT="$(awk '/^'user'$/{print; exit}' "$LOADED_PLUGINS_FILE" 2>/dev/null)"
if [ -z "$SP_OUT" ]; then
ocf_log err "Switch to userspace stack unsuccessful"
return $OCF_ERR_INSTALLED
fi
if [ -f "$CLUSTER_STACK_FILE" ]; then
echo "$OCF_RESKEY_stack" >"$CLUSTER_STACK_FILE"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Userspace stack '$OCF_RESKEY_stack' not supported"
return $OCF_ERR_INSTALLED
fi
else
ocf_log err "Switch to userspace stack not supported"
return $OCF_ERR_INSTALLED
fi
driver_filesystem ocfs2; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
modprobe -s ocfs2
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Unable to load ocfs2 module"
return $OCF_ERR_INSTALLED
fi
fi
bringup_daemon
return $?
}
o2cb_stop() {
o2cb_monitor; rc=$?
case $rc in
$OCF_NOT_RUNNING) return $OCF_SUCCESS;;
esac
ocf_log info "Stopping $OCF_RESOURCE_INSTANCE"
kill_daemon
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Unable to unload modules: the cluster is still online"
return $OCF_ERR_GENERIC
fi
unload_filesystem ocfs2
- if [ $? = 1 ]; then
+ if [ $? -eq 1 ]; then
ocf_log err "Unable to unload ocfs2 module"
return $OCF_ERR_GENERIC
fi
# If we can't find the stack glue, we have nothing to do.
[ ! -e "$LOADED_PLUGINS_FILE" ] && return $OCF_SUCCESS
while read plugin
do
unload_module "ocfs2_stack_${plugin}"
- if [ $? = 1 ]; then
+ if [ $? -eq 1 ]; then
ocf_log err "Unable to unload ocfs2_stack_${plugin}"
return $OCF_ERR_GENERIC
fi
done <"$LOADED_PLUGINS_FILE"
unload_module "ocfs2_stackglue"
- if [ $? = 1 ]; then
+ if [ $? -eq 1 ]; then
ocf_log err "Unable to unload ocfs2_stackglue"
return $OCF_ERR_GENERIC
fi
# Don't unmount configfs - it's always in use by libdlm
}
o2cb_monitor() {
o2cb_validate
# Assume that ocfs2_controld will terminate if any of the conditions below are met
driver_filesystem configfs; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
ocf_log info "configfs not loaded"
return $OCF_NOT_RUNNING
fi
check_filesystem configfs "${OCF_RESKEY_configfs}"; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
ocf_log info "configfs not mounted"
return $OCF_NOT_RUNNING
fi
if [ ! -e "$LOADED_PLUGINS_FILE" ]; then
ocf_log info "Stack glue driver not loaded"
return $OCF_NOT_RUNNING
fi
grep user "$LOADED_PLUGINS_FILE" >/dev/null 2>&1; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
ocf_log err "Wrong stack $(cat $LOADED_PLUGINS_FILE)"
return $OCF_ERR_INSTALLED
fi
driver_filesystem ocfs2; rc=$?
- if [ $rc != 0 ]; then
+ if [ $rc -ne 0 ]; then
ocf_log info "ocfs2 not loaded"
return $OCF_NOT_RUNNING
fi
status_daemon
return $?
}
o2cb_usage() {
echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
echo " Expects to have a fully populated OCF RA-compliant environment set."
echo " In particualr, a value for OCF_ROOT"
}
o2cb_validate() {
check_binary ${DAEMON}
case "${OCF_RESKEY_CRM_meta_globally_unique}" in
yes|Yes|true|True|1)
ocf_log err "$OCF_RESOURCE_INSTANCE must be configured with the globally_unique=false meta attribute"
exit $OCF_ERR_CONFIGURED
;;
esac
return $OCF_SUCCESS
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="o2cb" version="1.0">
<version>1.0</version>
<shortdesc lang="en">OCFS2 daemon resource agent</shortdesc>
<longdesc lang="en">
This Resource Agent controls the userspace daemon needed by OCFS2.
</longdesc>
<parameters>
<parameter name="sysfs" unique="0">
<longdesc lang="en">
Location where sysfs is mounted
</longdesc>
<shortdesc lang="en">Sysfs location</shortdesc>
<content type="string" default="/sys/fs"/>
</parameter>
<parameter name="configfs" unique="0">
<longdesc lang="en">
Location where configfs is mounted
</longdesc>
<shortdesc lang="en">Configfs location</shortdesc>
<content type="string" default="/sys/kernel/config"/>
</parameter>
<parameter name="stack" unique="0">
<longdesc lang="en">
Which userspace stack to use. Known values: pcmk
</longdesc>
<shortdesc lang="en">Userspace stack</shortdesc>
<content type="string" default="pcmk"/>
</parameter>
<parameter name="daemon_timeout" unique="0">
<longdesc lang="en">
Number of seconds to allow the control daemon to come up
</longdesc>
<shortdesc lang="en">Daemon Timeout</shortdesc>
<content type="string" default="10"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="90s" />
<action name="stop" timeout="100s" />
<action name="monitor" timeout="20s" depth="0"/>
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
}
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) o2cb_start
;;
stop) o2cb_stop
;;
monitor) o2cb_monitor
;;
validate-all) o2cb_validate
;;
usage|help) o2cb_usage
exit $OCF_SUCCESS
;;
*) o2cb_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/ping b/extra/resources/ping
index c7fd6da9d3..ab22e795e3 100755
--- a/extra/resources/ping
+++ b/extra/resources/ping
@@ -1,418 +1,418 @@
#!/bin/sh
#
# ocf:pacemaker:ping resource agent
#
# Copyright 2009-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
#######################################################################
# 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>1.0</version>
<longdesc lang="en">
Every time the monitor action is run, this resource agent records (in the CIB) the current number of nodes the host can connect to using the system fping (preferred) or ping tool.
</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="1"/>
</parameter>
<parameter name="host_list" unique="0" required="1">
<longdesc lang="en">
A space separated 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="3"/>
</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="use_fping" unique="0">
<longdesc lang="en">
Use fping rather than ping, if found. If set to 0, fping
will not be used even if present.
</longdesc>
<shortdesc lang="en">Use fping if available</shortdesc>
<content type="boolean" default="1"/>
</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="60s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="60s" interval="10s"/>
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
}
#######################################################################
ping_conditional_log() {
level="$1"; shift
if [ "${OCF_RESKEY_debug}" = "true" ]; then
ocf_log "$level" "$*"
fi
}
ping_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
ping_start() {
ping_monitor
- if [ $? = $OCF_SUCCESS ]; then
+ if [ $? -eq $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
touch "${OCF_RESKEY_pidfile}"
ping_update
}
ping_stop() {
rm -f "${OCF_RESKEY_pidfile}"
attrd_updater -D -n "$OCF_RESKEY_name" -d "$OCF_RESKEY_dampen" $attrd_options
return $OCF_SUCCESS
}
ping_monitor() {
if [ -f "${OCF_RESKEY_pidfile}" ]; then
ping_update
if [ $? -eq 0 ]; then
return $OCF_SUCCESS
fi
return $OCF_ERR_GENERIC
fi
return $OCF_NOT_RUNNING
}
ping_validate() {
# Is the state directory writable?
state_dir=$(dirname "$OCF_RESKEY_pidfile")
touch "$state_dir/$$"
- if [ $? != 0 ]; then
+ if [ $? -ne 0 ]; then
ocf_log err "Invalid location for 'state': $state_dir is not writable"
return $OCF_ERR_ARGS
fi
rm "$state_dir/$$"
# Pidfile better be an absolute path
case "$OCF_RESKEY_pidfile" in
/*) ;;
*) ocf_log warn "You should use an absolute path for pidfile not: $OCF_RESKEY_pidfile" ;;
esac
# Check the host list
- if [ "x" = "x$OCF_RESKEY_host_list" ]; then
+ if [ -z "$OCF_RESKEY_host_list" ]; then
ocf_log err "Empty host_list. Please specify some nodes to ping"
exit $OCF_ERR_CONFIGURED
fi
# For fping allow only same IP versions or hostnames
if use_fping; then
hosts_family
if [ $? -eq 99 ]; then
ocf_log err "host_list can contain only host with same IP versions for fping"
exit $OCF_ERR_CONFIGURED
fi
fi
check_binary ping
return $OCF_SUCCESS
}
fping_check() {
p_exe=fping
hosts_family
case $? in
6) p_exe=fping6 ;;
99) ocf_log err "Ambiguous IP versions in host_list: '$OCF_RESKEY_host_list'"; exit $OCF_ERR_CONFIGURED;;
esac
active=0
timeout=$(expr $OCF_RESKEY_timeout \* 1000 / $OCF_RESKEY_attempts)
cmd="$p_exe -r $OCF_RESKEY_attempts -t $timeout -B 1.0 $OCF_RESKEY_options $OCF_RESKEY_host_list"
output=$($cmd 2>&1); rc=$?
active=$(echo "$output" | grep "is alive" | wc -l)
case $rc in
0)
;;
1)
for h in $(echo "$output" | grep "is unreachable" | awk '{print $1}'); do
ping_conditional_log warn "$h is inactive"
done
;;
*)
ocf_log err "Unexpected result for '$cmd' $rc: $(echo "$output" | tr '\n' ';')"
;;
esac
return $active
}
ping_check() {
active=0
for host in $OCF_RESKEY_host_list; do
p_exe=ping
case $(uname) in
Linux) p_args="-n -q -W $OCF_RESKEY_timeout -c $OCF_RESKEY_attempts";;
Darwin) p_args="-n -q -t $OCF_RESKEY_timeout -c $OCF_RESKEY_attempts -o";;
FreeBSD) p_args="-n -q -t $OCF_RESKEY_timeout -c $OCF_RESKEY_attempts -o";;
*) ocf_log err "Unknown host type: $(uname)"; exit $OCF_ERR_INSTALLED;;
esac
case "$host" in
*:*) p_exe=ping6
esac
p_out=$($p_exe $p_args $OCF_RESKEY_options $host 2>&1); rc=$?
case $rc in
0) active=$(expr $active + 1);;
1) ping_conditional_log warn "$host is inactive: $p_out";;
*) ocf_log err "Unexpected result for '$p_exe $p_args $OCF_RESKEY_options $host' $rc: $p_out";;
esac
done
return $active
}
ping_update() {
if use_fping; then
fping_check
active=$?
else
ping_check
active=$?
fi
score=$(expr $active \* $OCF_RESKEY_multiplier)
if [ "$__OCF_ACTION" = "start" ] ; then
attrd_updater -n "$OCF_RESKEY_name" -B "$score" -d "$OCF_RESKEY_dampen" $attrd_options
else
attrd_updater -n "$OCF_RESKEY_name" -v "$score" -d "$OCF_RESKEY_dampen" $attrd_options
fi
rc=$?
case $rc in
0) ping_conditional_log debug "Updated $OCF_RESKEY_name = $score" ;;
*) ocf_log warn "Could not update $OCF_RESKEY_name = $score: rc=$rc";;
esac
if [ $rc -ne 0 ]; then
return $rc
fi
if [ -n "$OCF_RESKEY_failure_score" ] && [ "$score" -lt "$OCF_RESKEY_failure_score" ]; then
ocf_log warn "$OCF_RESKEY_name is less than failure_score($OCF_RESKEY_failure_score)"
return 1
fi
return 0
}
use_fping() {
ocf_is_true "$OCF_RESKEY_use_fping" && have_binary fping;
}
# return values:
# 4 IPv4
# 6 IPv6
# 0 indefinite (i.e. hostname)
host_family() {
case $1 in
*[0-9].*[0-9].*[0-9].*[0-9]) return 4 ;;
*:*) return 6 ;;
*) return 0 ;;
esac
}
# return values same as host_family plus
# 99 ambiguous families
hosts_family() {
# For fping allow only same IP versions or hostnames
family=0
for host in $OCF_RESKEY_host_list; do
host_family "$host"
f=$?
if [ $family -ne 0 ] && [ $f -ne 0 ] && [ $f -ne $family ] ; then
family=99
break
fi
[ $f -ne 0 ] && family=$f
done
return $family
}
: ${OCF_RESKEY_name:="pingd"}
: ${OCF_RESKEY_dampen:="5s"}
: ${OCF_RESKEY_attempts:="3"}
: ${OCF_RESKEY_multiplier:="1"}
: ${OCF_RESKEY_debug:="false"}
: ${OCF_RESKEY_failure_score:="0"}
: ${OCF_RESKEY_use_fping:="1"}
: ${OCF_RESKEY_CRM_meta_timeout:="20000"}
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
integer=$(echo ${OCF_RESKEY_timeout} | egrep -o '[0-9]*')
case "${OCF_RESKEY_timeout}" in
*[0-9]ms|*[0-9]msec) OCF_RESKEY_timeout=$(expr $integer / 1000);;
*[0-9]m|*[0-9]min) OCF_RESKEY_timeout=$(expr $integer \* 60);;
*[0-9]h|*[0-9]hr) OCF_RESKEY_timeout=$(expr $integer \* 60 \* 60);;
*) OCF_RESKEY_timeout=$integer;;
esac
if [ -z "${OCF_RESKEY_timeout}" ]; then
- if [ x"$OCF_RESKEY_host_list" != x ]; then
+ if [ -n "$OCF_RESKEY_host_list" ]; then
host_count=$(echo $OCF_RESKEY_host_list | awk '{print NF}')
OCF_RESKEY_timeout=$(expr $OCF_RESKEY_CRM_meta_timeout / $host_count / $OCF_RESKEY_attempts)
OCF_RESKEY_timeout=$(expr $OCF_RESKEY_timeout / 1100) # Convert to seconds and finish 10% early
else
OCF_RESKEY_timeout=5
fi
fi
if [ ${OCF_RESKEY_timeout} -lt 1 ]; then
OCF_RESKEY_timeout=5
elif [ ${OCF_RESKEY_timeout} -gt 1000 ]; then
# ping actually complains if this value is too high, 5 minutes is plenty
OCF_RESKEY_timeout=300
fi
if [ "${OCF_RESKEY_CRM_meta_globally_unique}" = "false" ]; then
: ${OCF_RESKEY_pidfile:="${HA_VARRUN%%/}/ping-${OCF_RESKEY_name}"}
else
: ${OCF_RESKEY_pidfile:="${HA_VARRUN%%/}/ping-${OCF_RESOURCE_INSTANCE}"}
fi
# Check the debug option
case "${OCF_RESKEY_debug}" in
true|True|TRUE|1) OCF_RESKEY_debug=true;;
false|False|FALSE|0) OCF_RESKEY_debug=false;;
*)
ocf_log warn "Value for 'debug' is incorrect. Please specify 'true' or 'false' not: ${OCF_RESKEY_debug}"
OCF_RESKEY_debug=false
;;
esac
attrd_options='-q'
if [ "${OCF_RESKEY_debug}" = "true" ]; then
attrd_options=''
fi
case "$__OCF_ACTION" in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) ping_start;;
stop) ping_stop;;
monitor) ping_monitor;;
validate-all) ping_validate;;
usage|help) ping_usage
exit $OCF_SUCCESS
;;
*) ping_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:
diff --git a/extra/resources/pingd b/extra/resources/pingd
index 8f448c1b22..77617ce3ed 100755
--- a/extra/resources/pingd
+++ b/extra/resources/pingd
@@ -1,189 +1,189 @@
#!/bin/sh
#
# ocf:pacemaker:pingd resource agent
#
# Copyright 2006-2019 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# (GPLv2) WITHOUT ANY WARRANTY.
#
#
# Records (in the CIB) the current number of ping nodes a cluster node can
# connect to.
#
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS:="${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"}
. "${OCF_FUNCTIONS}"
: ${__OCF_ACTION:="$1"}
: ${OCF_RESKEY_name:="pingd"}
: ${OCF_RESKEY_interval:="1"}
: ${OCF_RESKEY_CRM_meta_interval:=0}
upgrade1="This agent (ocf:pacemaker:pingd) has been replaced by the more reliable ocf:pacemaker:ping."
upgrade2="Attempting automated conversion, run 'crm ra info ocf:pacemaker:ping' for all configuration options"
upgrade3="You will need to remove the existing resource and replace it with one that uses 'ocf:pacemaker:ping' directly"
case "$__OCF_ACTION" in
start|monitor)
- if [ "x" != "x$OCF_RESKEY_host_list" ]; then
+ if [ -n "$OCF_RESKEY_host_list" ]; then
ocf_log err "$upgrade1"
ocf_log err "$upgrade2"
ocf_log err "Automatic conversion to ocf:pacemaker:ping failed: no hosts were configured to check for connectivity"
ocf_log err "$upgrade3"
exit $OCF_ERR_ARGS
fi
recurring=$(crm configure show "$OCF_RESOURCE_INSTANCE" | grep "op monitor.*interval=\"[1-9]" | sed s/.*interval=// | awk -F\" '{print $2}' | sed s/.*interval=// | awk -F\" '{print $2}' | sort | head -n 1)
if [ -z "$recurring" ]; then
ocf_log err "$upgrade1"
ocf_log err "$upgrade2"
ocf_log err "Automatic conversion to ocf:pacemaker:ping failed: no monitor operation configured"
ocf_log err "Without an explicit monitor operation for '$OCF_RESOURCE_INSTANCE', connectivity changes will not be noticed"
ocf_log err "Preventing startup to ensure the issue is addressed before it matters"
exit $OCF_ERR_ARGS
fi
- if [ $OCF_RESKEY_CRM_meta_interval = 0 ]; then
+ if [ $OCF_RESKEY_CRM_meta_interval -eq 0 ]; then
ocf_log warn "$upgrade1"
ocf_log warn "$upgrade2"
- if [ $recurring != $OCF_RESKEY_interval ]; then
+ if [ $recurring -ne $OCF_RESKEY_interval ]; then
ocf_log warn "Your monitor operation happens every $recurring, which means that the $OCF_RESKEY_name attribute will be updated with a different frequency than the previously configured ( $OCF_RESKEY_interval )"
ocf_log warn "Either change the monitor interval to match or, ideally, switch to the ocf:pacemaker:ping agent and avoid all this compatibility nonsense."
fi
fi
;;
meta-data)
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="pingd" version="1.0">
<version>1.0</version>
<longdesc lang="en">
This agent (ocf:pacemaker:pingd) has been replaced by the more reliable ocf:pacemaker:ping.
It records (in the CIB) the current number of ping nodes (specified in the 'host_list' parameter) a cluster node can connect to.
</longdesc>
<shortdesc lang="en">pingd resource agent</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%%1}/pingd-${OCF_RESOURCE_INSTANCE}" />
</parameter>
<parameter name="user" unique="0">
<longdesc lang="en">
The user we want to run pingd as
</longdesc>
<shortdesc lang="en">The user we want to run pingd as</shortdesc>
<content type="string" default="root" />
</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="set" unique="0">
<longdesc lang="en">
The name of the instance_attributes set to place the value in. Rarely needs to be specified.
</longdesc>
<shortdesc lang="en">Set name</shortdesc>
<content type="string" default=""/>
</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="section" unique="0">
<longdesc lang="en">
The section place the value in. Rarely needs to be specified.
</longdesc>
<shortdesc lang="en">Section name</shortdesc>
<content type="string" default=""/>
</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">
<longdesc lang="en">
The list of ping nodes to count. Defaults to all configured ping nodes. Rarely needs to be specified.
</longdesc>
<shortdesc lang="en">Host list</shortdesc>
<content type="string" default=""/>
</parameter>
<parameter name="interval" unique="0">
<longdesc lang="en">
How often, in seconds, to check for node liveliness
</longdesc>
<shortdesc lang="en">ping interval in seconds</shortdesc>
<content type="integer" default="1"/>
</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 pingd.
</longdesc>
<shortdesc lang="en">Extra Options</shortdesc>
<content type="string" default=""/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="90s" />
<action name="stop" timeout="100s" />
<action name="monitor" depth="0" timeout="20s" interval="10s" start-delay="1m" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="30s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
;;
esac
"${OCF_ROOT}/resource.d/pacemaker/ping" "$1"
exit $?
# vim: set filetype=sh expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80:

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 5:01 PM (11 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1019022
Default Alt Text
(94 KB)

Event Timeline