From 7de03e4e519705301265c0415b3c0af85263a7ac Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:52:36 +0200 Subject: Adding upstream version 1:4.13.0. Signed-off-by: Daniel Baumann --- heartbeat/Stateful | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100755 heartbeat/Stateful (limited to 'heartbeat/Stateful') diff --git a/heartbeat/Stateful b/heartbeat/Stateful new file mode 100755 index 0000000..72dd550 --- /dev/null +++ b/heartbeat/Stateful @@ -0,0 +1,192 @@ +#!/bin/sh +# +# +# Example of a stateful OCF Resource Agent. +# +# Copyright (c) 2006 Andrew Beekhof +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Further, this software is distributed without any warranty that it is +# free of the rightful claim of any third person regarding infringement +# or the like. Any license provided herein, whether implied or +# otherwise, applies only to this software file. Patent licenses, if +# any, provided herein do not apply to combinations of this program with +# other software, or any other product whatsoever. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. +# + +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +# Parameter defaults + +OCF_RESKEY_state_default="${HA_RSCTMP}/Stateful-${OCF_RESOURCE_INSTANCE}.state" + +: ${OCF_RESKEY_state=${OCF_RESKEY_state_default}} + +####################################################################### + +meta_data() { + cat < + + +1.0 + + +This is an example resource agent that implements two states + +Example stateful resource agent + + + + + +Location to store the resource state in + +State file + + + + + + + + + + + + + + + +END + exit $OCF_SUCCESS +} + +####################################################################### + +stateful_usage() { + cat < ${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 + return $OCF_SUCCESS + fi + + else + if [ "x$target" = "x" ]; then + return $OCF_SUCCESS + fi + fi + + return $OCF_ERR_GENERIC +} + +stateful_start() { + stateful_check_state master + if [ $? = 0 ]; then + # CRM Error - Should never happen + return $OCF_RUNNING_MASTER + fi + stateful_update slave + ocf_promotion_score -v 5 + return $OCF_SUCCESS +} + +stateful_demote() { + stateful_check_state + if [ $? = 0 ]; then + # CRM Error - Should never happen + return $OCF_NOT_RUNNING + fi + stateful_update slave + ocf_promotion_score -v 5 + return $OCF_SUCCESS +} + +stateful_promote() { + stateful_check_state + if [ $? = 0 ]; then + return $OCF_NOT_RUNNING + fi + stateful_update master + ocf_promotion_score -v 10 + return $OCF_SUCCESS +} + +stateful_stop() { + ocf_promotion_score -D + stateful_check_state master + if [ $? = 0 ]; then + # CRM Error - Should never happen + return $OCF_RUNNING_MASTER + fi + if [ -f ${OCF_RESKEY_state} ]; then + rm ${OCF_RESKEY_state} + fi + return $OCF_SUCCESS +} + +stateful_monitor() { + stateful_check_state "master" + if [ $? = 0 ]; then + return $OCF_RUNNING_MASTER + fi + + stateful_check_state "slave" + if [ $? = 0 ]; then + 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 $OCF_NOT_RUNNING +} + +stateful_validate() { + exit $OCF_SUCCESS +} + +case $__OCF_ACTION in +meta-data) meta_data;; +start) stateful_start;; +promote) stateful_promote;; +demote) stateful_demote;; +stop) stateful_stop;; +monitor) stateful_monitor;; +validate-all) stateful_validate;; +usage|help) stateful_usage $OCF_SUCCESS;; +*) stateful_usage $OCF_ERR_UNIMPLEMENTED;; +esac + +exit $? -- cgit v1.2.3