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 eb72e3d82..7213b32c4 100644
--- a/heartbeat/Delay.in
+++ b/heartbeat/Delay.in
@@ -1,225 +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
#######################################################################
-HA_VARRUNHBRSCDIR=@HA_VARRUNHBRSCDIR@
-VLFILE="$HA_VARRUNHBRSCDIR/Delay-${OCF_RESOURCE_INSTANCE}"
-
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() {
- test -f "$VLFILE"
+ 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
- touch "$VLFILE"
+ ha_pseudo_resource Delay_${OCF_RESKEY_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
- unlink "$VLFILE"
+ ha_pseudo_resource Delay_${OCF_RESKEY_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 7ffef4b37..adb332747 100644
--- a/heartbeat/Dummy.in
+++ b/heartbeat/Dummy.in
@@ -1,159 +1,199 @@
#!/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
+Location to store the resource state in.
</longdesc>
<shortdesc lang="en">State file</shortdesc>
-<content type="string" default="@HA_VARRUNHBRSCDIR@/Dummy-{OCF_RESOURCE_INSTANCE}.state" />
+<content type="string" default="" />
+</parameter>
+
+<parameters>
+<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>
</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|validate-all|meta-data}
+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() {
- sleep $OCF_RESKEY_delay
- if [ -f ${OCF_RESKEY_state} ]; then
- return 0
- fi
- touch ${OCF_RESKEY_state}
+ sleepsleep $OCF_RESKEY_delay
+ ha_pseudo_resource Dummy_${OCF_RESKEY_instance} start ${OCF_RESKEY_state}
}
dummy_stop() {
- sleep $OCF_RESKEY_delay
- if [ -f ${OCF_RESKEY_state} ]; then
- rm ${OCF_RESKEY_state}
- fi
- return 0
+ sleepsleep $OCF_RESKEY_delay
+ ha_pseudo_resource Dummy_${OCF_RESKEY_instance} stop ${OCF_RESKEY_state}
}
dummy_monitor() {
- sleep $OCF_RESKEY_delay
- if [ -f ${OCF_RESKEY_state} ]; then
- return 0
- fi
- return 7
+ sleepsleep $OCF_RESKEY_delay
+ ha_pseudo_resource Dummy_${OCF_RESKEY_instance} monitor ${OCF_RESKEY_state}
}
dummy_validate() {
exit $OC_ERR_UNIMPLEMENTED
}
: ${OCF_RESKEY_delay=1}
-: ${OCF_RESKEY_state=@HA_VARRUNHBRSCDIR@/Dummy-${OCF_RESOURCE_INSTANCE}.state}
+: ${OCF_RESKEY_check_parallel=1}
+
+lockf=`
+ 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
+
+echo $$ > $lockf
+trap "rm -f $lockf" EXIT
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
diff --git a/heartbeat/MailTo.in b/heartbeat/MailTo.in
index 0d317f032..68ac3a873 100644
--- a/heartbeat/MailTo.in
+++ b/heartbeat/MailTo.in
@@ -1,214 +1,209 @@
#!/bin/sh
#
# Resource script for MailTo
#
# Author: Alan Robertson <alanr@unix.sh>
#
# Description: sends email to a sysadmin whenever a takeover occurs.
#
# Note: This command requires an argument, unlike normal init scripts.
#
# This can be given in the haresources file as:
#
# You can also give a mail subject line or even multiple addresses
# MailTo::alanr@unix.sh::BigImportantWebServer
# MailTo::alanr@unix.sh,spoppi@gmx.de::BigImportantWebServer
#
# This will then be put into the message subject and body.
#
# OCF parameters are as below:
# OCF_RESKEY_email
# OCF_RESKEY_subject
#
# License: GNU General Public License (GPL)
#
# Copyright: (C) 2005 International Business Machines
-MAILTOFILE=@HA_VARRUNDIR@/MailTo
#######################################################################
# Initialization:
. @hb_libdir@/ocf-shellfuncs
#######################################################################
ARGS="$0 $*"
us=`uname -n`
usage() {
echo "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="MailTo">
<version>1.0</version>
<longdesc lang="en">
This is a resource agent for MailTo. It sends email to a sysadmin whenever
a takeover occurs.
</longdesc>
<shortdesc lang="en">MailTo resource agent</shortdesc>
<parameters>
<parameter name="email" unique="0" required="1">
<longdesc lang="en">
The email address of sysadmin.
</longdesc>
<shortdesc lang="en">Email address</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="subject" unique="0">
<longdesc lang="en">
The subject of the email.
</longdesc>
<shortdesc lang="en">Subject</shortdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="10" />
<action name="stop" timeout="10" />
<action name="status" depth="0" timeout="10" interval="10" start-delay="10" />
<action name="monitor" depth="0" timeout="10" interval="10" start-delay="10" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
</actions>
</resource-agent>
END
}
MailProgram() {
mail -s "$1" "$email" <<EOF
$Subject
Command line was:
$ARGS
EOF
return $?
}
SubjectLine() {
case $1 in
??*) echo $1;;
*) echo "Resource Group";;
esac
}
MailToStart() {
Subject="`SubjectLine $subject` Takeover in progress at `date` on $us"
MailProgram "$Subject" $1
- touch $MAILTOFILE
- return $?
+ ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} start
}
MailToStop () {
Subject="`SubjectLine $subject` Migrating resource away at `date` from $us"
MailProgram "$Subject" $1
- rm -f $MAILTOFILE
- return $?
+ ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} stop
}
MailToStatus () {
ocf_log warn "Don't stat/monitor me! MailTo is a pseudo resource agent, so the status reported may be incorrect"
- if [ -f $MAILTOFILE ]; then
+ if ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} monitor
+ then
echo "running"
return $OCF_SUCCESS
else
echo "stopped"
return $OCF_NOT_RUNNING
fi
}
MailToValidateAll () {
# $email may be a list of mail addresses separated by "," and " " and "\t"
# normalize it for ease of parse
local local_email=`echo $email | tr ",\t" " " | tr -s " "`
# ocf_log info "[$local_email]"
for item in "$local_email"
do
case $item in
*?@?*)
;; #possible valid email address
*)
getent passwd $item >/dev/null
if [ $? -eq 0 ]; then
: OK, mail to $item@localhost.localdomain
else
ocf_log err "Invalid email address [$email]"
exit $OCF_ERR_ARGS
fi
;;
esac
done
# Any subject is OK
return $OCF_SUCCESS
}
#
# See how we were called.
#
# The order in which heartbeat provides arguments to resource
# scripts is broken. It should be fixed.
#
if
( [ $# -ne 1 ] )
then
usage
exit $OCF_ERR_GENERIC
fi
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
- # Not quite sure what to do with this one...
- # We aren't a continuously running service - so it's not clear
- #
status|monitor) MailToStatus
exit $?
;;
usage) usage
exit $OCF_SUCCESS
;;
*) ;;
esac
if
[ -z "$OCF_RESKEY_email" ]
then
ocf_log err "At least 1 Email address has to be given!"
# usage
exit $OCF_ERR_GENERIC
fi
email=$OCF_RESKEY_email
subject=$OCF_RESKEY_subject
case $1 in
start) MailToStart
;;
stop) MailToStop
;;
validate-all) MailToValidateAll
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 26, 11:21 PM (8 h, 21 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1465877
Default Alt Text
(16 KB)

Event Timeline