Page MenuHomeClusterLabs Projects

No OneTemporary

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
diff --git a/heartbeat/Delay.in b/heartbeat/Delay.in
index 7213b32c4..072688967 100644
--- a/heartbeat/Delay.in
+++ b/heartbeat/Delay.in
@@ -1,222 +1,222 @@
#!/bin/sh
#
#
# Support: linux-ha@lists.linux-ha.org
# License: GNU General Public License (GPL)
#
# This script is a test resource for introducing delay.
#
# usage: $0 {start|stop|status|monitor|meta-data}
#
# OCF parameters are as below:
# OCF_RESKEY_startdelay
# OCF_RESKEY_stopdelay
# OCF_RESKEY_mondelay
#
#
# OCF_RESKEY_startdelay defaults to 30 (seconds)
# OCF_RESKEY_stopdelay defaults to $OCF_RESKEY_startdelay
# OCF_RESKEY_mondelay defaults to $OCF_RESKEY_startdelay
#
#
# This is really a test resource script.
#
#######################################################################
# Initialization:
. @hb_libdir@/ocf-shellfuncs
#######################################################################
usage() {
cat <<-!
usage: $0 {start|stop|status|monitor|meta-data|validate-all}
!
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="Delay">
<version>1.0</version>
<longdesc lang="en">
This script is a test resource for introducing delay.
</longdesc>
<shortdesc lang="en">Delay resource agent</shortdesc>
<parameters>
<parameter name="startdelay" unique="0" required="1">
<longdesc lang="en">
How long in seconds to delay on start operation.
</longdesc>
<shortdesc lang="en">Start delay</shortdesc>
<content type="integer" default="30" />
</parameter>
<parameter name="stopdelay" unique="0" required="1">
<longdesc lang="en">
How long in seconds to delay on stop operation.
Defaults to "startdelay" if unspecified.
</longdesc>
<shortdesc lang="en">Stop delay</shortdesc>
<content type="integer" default="30" />
</parameter>
<parameter name="mondelay" unique="0" required="1">
<longdesc lang="en">
How long in seconds to delay on monitor operation.
Defaults to "startdelay" if unspecified.
</longdesc>
<shortdesc lang="en">Monitor delay</shortdesc>
<content type="integer" default="30" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="30" />
<action name="stop" timeout="30" />
<action name="status" depth="0" timeout="30" interval="10" start-delay="30" />
<action name="monitor" depth="0" timeout="30" interval="10" start-delay="30" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
</actions>
</resource-agent>
END
}
Delay_stat() {
ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} monitor
}
Delay_Status() {
if
Delay_stat
then
ocf_log info "Delay is running OK"
return $OCF_SUCCESS
else
ocf_log info "Delay is stopped"
return $OCF_NOT_RUNNING
fi
}
Delay_Monitor() {
Delay_Validate_All -q
sleep $OCF_RESKEY_mondelay
Delay_Status
}
Delay_Start() {
if
Delay_stat
then
ocf_log info "Delay already running."
return $OCF_SUCCESS
else
Delay_Validate_All -q
- ha_pseudo_resource Delay_${OCF_RESKEY_instance} start
+ ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} start
rc=$?
sleep $OCF_RESKEY_startdelay
if
[ $rc -ne 0 ]
then
return $OCF_ERR_PERM
fi
return $OCF_SUCCESS
fi
}
Delay_Stop() {
if
Delay_stat
then
Delay_Validate_All -q
- ha_pseudo_resource Delay_${OCF_RESKEY_instance} stop
+ ha_pseudo_resource Delay_${OCF_RESOURCE_INSTANCE} stop
rc=$?
sleep $OCF_RESKEY_stopdelay
if
[ $rc -ne 0 ]
then
return $OCF_ERR_PERM
fi
return $OCF_SUCCESS
else
ocf_log info "Delay already stopped."
return $OCF_SUCCESS
fi
}
# Check if all the arguments are valid numbers, a string is considered valid if:
# 1. It does not contain any character but digits and period ".";
# 2. The period "." does not occur more than once
Are_Valid_Numbers() {
for i in "$@"; do
echo $i |grep -v [^0-9.] |grep -q -v [.].*[.]
if test $? -ne 0; then
return $OCF_ERR_ARGS
fi
done
return $OCF_SUCCESS
}
Delay_Validate_All() {
# Be quiet when specified -q option _and_ validation succeded
getopts "q" option
if test $option = "q"; then
quiet=yes
else
quiet=no
fi
shift $(($OPTIND -1))
if Are_Valid_Numbers $OCF_RESKEY_startdelay $OCF_RESKEY_stopdelay \
$OCF_RESKEY_mondelay; then
if test $quiet = "no"; then
echo "Validate OK"
fi
# _Return_ on validation success
return $OCF_SUCCESS
else
echo "Some of the instance parameters are invalid"
# _Exit_ on validation failure
exit $OCF_ERR_ARGS
fi
}
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
: ${OCF_RESKEY_startdelay=30}
: ${OCF_RESKEY_stopdelay=$OCF_RESKEY_startdelay}
: ${OCF_RESKEY_mondelay=$OCF_RESKEY_startdelay}
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) Delay_Start
;;
stop) Delay_Stop
;;
monitor) Delay_Monitor
;;
status) Delay_Status
;;
validate-all) Delay_Validate_All
;;
usage) usage
exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_ARGS
;;
esac
exit $?
diff --git a/heartbeat/Dummy.in b/heartbeat/Dummy.in
index 3de49c17d..b00be7ed0 100644
--- a/heartbeat/Dummy.in
+++ b/heartbeat/Dummy.in
@@ -1,198 +1,223 @@
#!/bin/sh
#
#
# Dummy OCF RA. Does nothing but wait a few seconds, can be
# configured to fail occassionally.
#
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Br馥
# 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:
. @hb_libdir@/ocf-shellfuncs
#######################################################################
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="Dummy" version="0.9">
<version>1.0</version>
<longdesc lang="en">
This is a Dummy Resource Agent. It does absolutely nothing except wait
for various amounts of time on execution.
</longdesc>
<shortdesc lang="en">Dummy resource agent</shortdesc>
<parameters>
<parameter name="delay" unique="0">
<longdesc lang="en">
How long to delay before each action.
</longdesc>
<shortdesc lang="en">Action delay</shortdesc>
<content type="integer" default="5" />
</parameter>
<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="" />
</parameter>
<parameter name="check_parallel" unique="0">
<longdesc lang="en">
Complain loudly if they try to run us in parallel on the same resource.
</longdesc>
<shortdesc lang="en">Report error if run twice at the same time</shortdesc>
<content type="boolean" default="true" />
</parameter>
+<parameter name="ignore_TERM" unique="0">
+<longdesc lang="en">
+Process the TERM signal and don't exit.
+</longdesc>
+<shortdesc lang="en">No TERM ain't gonna kill us.</shortdesc>
+<content type="boolean" default="false" />
+</parameter>
+
+<parameter name="verbose" unique="0">
+<longdesc lang="en">
+Print more information.
+</longdesc>
+<shortdesc lang="en">Be verbose.</shortdesc>
+<content type="boolean" default="false" />
+</parameter>
+
</parameters>
<actions>
<action name="start" timeout="90" />
<action name="stop" timeout="100" />
<action name="monitor" timeout="20" interval="10" depth="0" start-delay="0" />
<action name="reload" timeout="90" />
<action name="migrate_to" timeout="100" />
<action name="migrate_from" timeout="90" />
<action name="meta-data" timeout="5" />
<action name="verify-all" timeout="30" />
</actions>
</resource-agent>
END
}
#######################################################################
# don't exit on TERM, to test that lrmd makes sure that we do exit
-trap sigterm_handler TERM
sigterm_handler() {
ocf_log info "They use TERM to bring us down. No such luck."
return
}
dummy_usage() {
cat <<END
usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
-# dejan said: what is this for?
-#
-dummy_exit() {
- if [ -e /tmp/Dummy.$__OCF_ACTION ]; then
- exit $OCF_ERR_GENERIC
- else
- exit $1
- fi
-}
-
# signals interrupt slow calls (sleep)
# this is an approximation (after all it's just a dummy)
sleepsleep() {
delay=$1
now=`perl -e 'print time()'`
by=$((now+delay))
while [ $now -lt $by ]; do
ocf_log debug "Gonna sleep for $((by-now)) seconds..."
sleep $((by-now))
now=`perl -e 'print time()'`
done
}
dummy_start() {
sleepsleep $OCF_RESKEY_delay
- ha_pseudo_resource Dummy_${OCF_RESKEY_instance} start ${OCF_RESKEY_state}
+ ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} start $OCF_RESKEY_state
}
dummy_stop() {
sleepsleep $OCF_RESKEY_delay
- ha_pseudo_resource Dummy_${OCF_RESKEY_instance} stop ${OCF_RESKEY_state}
+ ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} stop $OCF_RESKEY_state
}
dummy_monitor() {
sleepsleep $OCF_RESKEY_delay
- ha_pseudo_resource Dummy_${OCF_RESKEY_instance} monitor ${OCF_RESKEY_state}
+ ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} monitor $OCF_RESKEY_state
}
dummy_validate() {
exit $OC_ERR_UNIMPLEMENTED
}
+verbose() {
+ [ "$OCF_RESKEY_verbose" != 0 ]
+}
+environment() {
+ echo "OCF environment variables:"
+ set | egrep 'OCF_RESKEY|OCF_RESOURCE_INSTANCE'
+}
+invocation() {
+ echo "invoked with args: $@"
+}
+
: ${OCF_RESKEY_delay=1}
: ${OCF_RESKEY_check_parallel=1}
+: ${OCF_RESKEY_verbose=0}
+: ${OCF_RESKEY_ignore_TERM=0}
+
+verbose && environment
lockf=`
- ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} print ${OCF_RESKEY_state} |
+ ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} print $OCF_RESKEY_state |
sed 's/$/.lock/'
`
check4parallel() {
if [ -f "$lockf" ] && kill -0 `cat $lockf` 2>/dev/null
then
ocf_log err "There is another instance of ${OCF_RESOURCE_INSTANCE} running: pid `cat $lockf`."
exit $OCF_ERR_GENERIC
fi
}
[ "$OCF_RESKEY_check_parallel" = 1 ] &&
check4parallel
+[ "$OCF_RESKEY_ignore_TERM" = 1 ] &&
+ trap sigterm_handler TERM
+
echo $$ > $lockf
trap "rm -f $lockf" EXIT
+verbose && invocation $@
+
case $__OCF_ACTION in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) dummy_start;;
stop) dummy_stop;;
monitor) dummy_monitor;;
migrate_to) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_to}."
dummy_stop
;;
migrate_from) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrated_from}."
dummy_start
;;
reload) ocf_log err "Reloading..."
dummy_start
;;
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"
-dummy_exit $rc
+exit $rc
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
index caba92119..6a0591d82 100644
--- a/heartbeat/ocf-shellfuncs.in
+++ b/heartbeat/ocf-shellfuncs.in
@@ -1,206 +1,210 @@
#
#
# Common helper functions for the OCF Resource Agents supplied by
# heartbeat.
#
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Br馥
# All Rights Reserved.
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# TODO: Some of this should probably split out into a generic OCF
# library for shell scripts, but for the time being, we'll just use it
# ourselves...
#
# TODO wish-list:
# - Generic function for evaluating version numbers
# - Generic function(s) to extract stuff from our own meta-data
# - Logging function which automatically adds resource identifier etc
# prefixes
# TODO: Move more common functionality for OCF RAs here.
#
# This was common throughout all legacy Heartbeat agents
unset LC_ALL; export LC_ALL
unset LANGUAGE; export LANGUAGE
__SCRIPT_NAME=`basename $0`
. @HA_HBCONF_DIR@/shellfuncs
. @hb_libdir@/ocf-returncodes
ocf_is_root() {
case `id` in
*'uid=0(root)'*) true;;
*) false;;
esac
}
# Portability comments:
# o The following rely on Bourne "sh" pattern-matching, which is usually
# that for filename generation (note: not regexp).
# o The "*) true ;;" clause is probably unnecessary, but is included
# here for completeness.
# o The negation in the pattern uses "!". This seems to be common
# across many OSes (whereas the alternative "^" fails on some).
# o If an OS is encountered where this negation fails, then a possible
# alternative would be to replace the function contents by (e.g.):
# [ -z "`echo $1 | tr -d '[0-9]'`" ]
#
ocf_is_decimal() {
case "$1" in
""|*[!0-9]*) # empty, or at least one non-decimal
false ;;
*)
true ;;
esac
}
ocf_is_hex() {
case "$1" in
""|*[!0-9a-fA-F]*) # empty, or at least one non-hex
false ;;
*)
true ;;
esac
}
ocf_is_octal() {
case "$1" in
""|*[!0-7]*) # empty, or at least one non-octal
false ;;
*)
true ;;
esac
}
__ocf_set_defaults() {
__OCF_ACTION="$1"
# Return to sanity for the agents...
unset LANG
LC_ALL=C
export LC_ALL
# TODO: Review whether we really should source this. Or rewrite
# to match some emerging helper function syntax...? This imports
# things which no OCF RA should be using...
# Strip the OCF_RESKEY_ prefix from this particular parameter
if [ -z "$OCF_RESKEY_OCF_CHECK_LEVEL" ]; then
: ${OCF_CHECK_LEVEL:=0}
else
: ${OCF_CHECK_LEVEL:=$OCF_RESKEY_OCF_CHECK_LEVEL}
fi
if [ -z "$OCF_ROOT" ]; then
: ${OCF_ROOT=@OCF_ROOT_DIR@}
fi
if [ ! -d "$OCF_ROOT" ]; then
ha_log "ERROR: OCF_ROOT points to non-directory $OCF_ROOT."
exit $OCF_ERR_GENERIC
fi
if [ -z "$OCF_RESOURCE_TYPE" ]; then
: ${OCF_RESOURCE_TYPE:=$__SCRIPT_NAME}
fi
if [ -z "$OCF_RA_VERSION_MAJOR" ]; then
: We are being invoked as an init script.
: Fill in some things with reasonable values.
: ${OCF_RESOURCE_INSTANCE:="default"}
return 0
fi
# TODO: Anything else we should be setting and thus checking?
# There is nothing in this script which depends on the version
# of the API. TESTING THIS HERE IS A BUG. THIS SHOULD BE
# tested by the script that's invoked us. FIXME!!
if [ "x$OCF_RA_VERSION_MAJOR" != "x1" ]; then
ha_log "ERROR: This script is OCF RA API 1.x compliant only!"
exit $OCF_ERR_UNIMPLEMENTED
fi
# TODO: Should the minor level really be a number and not rather
# a list of flags...?
# AlanR says -- absolutely not -- a list of flags is good for a list
# of implemented features, not a version compiliance
# perhaps some future version might have such a list of
# flags, but that would be _in addition to_ the minor version number
if [ -z "$OCF_RA_VERSION_MINOR" ]; then
ha_log "ERROR: No OCF RA minor version set."
exit $OCF_ERR_UNIMPLEMENTED
fi
if [ "x$__OCF_ACTION" = "xmeta-data" ]; then
OCF_RESOURCE_INSTANCE="undef"
fi
if [ -z "$OCF_RESOURCE_INSTANCE" ]; then
ha_log "ERROR: Need to tell us our resource instance name."
exit $OCF_ERR_ARGS
fi
}
ocf_log() {
# TODO: Revisit and implement internally.
if
[ $# -lt 2 ]
then
ocf_log err "Not enough arguments [$#] to ocf_log."
fi
__OCF_PRIO="$1"
shift
__OCF_MSG="$*"
case "${__OCF_PRIO}" in
crit) __OCF_PRIO="CRIT";;
err) __OCF_PRIO="ERROR";;
warn) __OCF_PRIO="WARNING";;
info) __OCF_PRIO="INFO";;
debug)__OCF_PRIO="DEBUG";;
*) __OCF_PRIO=`echo ${__OCF_PRIO}| tr '[a-z]' '[A-Z]'`;;
esac
- ha_log "${__OCF_PRIO}: $__OCF_MSG"
+ if [ "${__OCF_PRIO}" = "DEBUG" ]; then
+ ha_debug "${__OCF_PRIO}: $__OCF_MSG"
+ else
+ ha_log "${__OCF_PRIO}: $__OCF_MSG"
+ fi
}
#
# Ocf_run: Run a script, and log its output.
# Usage: ocf_run <command>
#
ocf_run() {
output=`"$@" 2>&1`
rc=$?
output=`echo $output`
if [ $rc -eq 0 ]; then
if [ ! -z "$output" ]; then
ocf_log info "$output"
fi
return $OCF_SUCCESS
else
if [ ! -z "$output" ]; then
ocf_log err "$output"
else
ocf_log err "command failed: $*"
fi
return $OCF_ERR_GENERIC
fi
}
__ocf_set_defaults "$@"

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 26, 4:00 PM (10 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1459368
Default Alt Text
(17 KB)

Event Timeline