From aa75500a03f23379b943a1796a72e3853ad18440 Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Fri, 4 Nov 2011 12:46:25 +0000 Subject: [PATCH] Add ganeti-master-role.ocf example file This allows controlling the cluster master role if the nodes are part of a linux-HA cluster. Signed-off-by: Guido Trotter Reviewed-by: Michael Hanselmann --- .gitignore | 1 + Makefile.am | 1 + devel/upload | 4 + doc/examples/ganeti-master-role.ocf.in | 129 +++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 doc/examples/ganeti-master-role.ocf.in diff --git a/.gitignore b/.gitignore index 06c5eba65..ebd14918c 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ /doc/examples/ganeti.cron /doc/examples/ganeti.initd /doc/examples/ganeti-kvm-poweroff.initd +/doc/examples/ganeti-master-role.ocf /doc/examples/gnt-config-backup /doc/examples/hooks/ipsec diff --git a/Makefile.am b/Makefile.am index 2ca6ed775..c447dcb37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -208,6 +208,7 @@ BUILT_EXAMPLES = \ doc/examples/ganeti-kvm-poweroff.initd \ doc/examples/ganeti.cron \ doc/examples/ganeti.initd \ + doc/examples/ganeti-master-role.ocf \ doc/examples/gnt-config-backup \ doc/examples/hooks/ipsec diff --git a/devel/upload b/devel/upload index 5fe1c7462..0b2da1248 100755 --- a/devel/upload +++ b/devel/upload @@ -99,6 +99,10 @@ PKGLIBDIR="$(echo @PKGLIBDIR@ | $SED)" install -D --mode=0755 doc/examples/ganeti.initd \ "$TXD/$SYSCONFDIR/init.d/ganeti" +[ -f doc/examples/ganeti-master-role.ocf ] && \ +install -D --mode=0755 doc/examples/ganeti-master-role.ocf \ + "$TXD/$LIBDIR/ocf/resource.d/ganeti/ganeti-master-role" + [ -f doc/examples/ganeti.default-debug -a -z "$NO_DEBUG" ] && \ install -D --mode=0644 doc/examples/ganeti.default-debug \ "$TXD/$SYSCONFDIR/default/ganeti" diff --git a/doc/examples/ganeti-master-role.ocf.in b/doc/examples/ganeti-master-role.ocf.in new file mode 100644 index 000000000..23f2f6f86 --- /dev/null +++ b/doc/examples/ganeti-master-role.ocf.in @@ -0,0 +1,129 @@ +#!/bin/bash +# ganeti master role OCF resource +# See http://linux-ha.org/wiki/OCF_Resource_Agents + +set -e -u + +@SHELL_ENV_INIT@ + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +SCRIPTNAME="@LIBDIR@/ocf/resource.d/ganeti/ganeti-master-role" + +# Master candidates list file +MCFILE="$DATA_DIR/ssconf_master_candidates" + +# We'll need the hostname in a few places, so we'll get it once, now. +MYHOSTNAME=$(hostname --fqdn) + +is_master() { + local -r master=$(gnt-cluster getmaster) + [[ "$MYHOSTNAME" == "$master" ]] +} + +is_candidate() { + grep -Fx $MYHOSTNAME $MCFILE +} + +start_action() { + if is_master; then + exit 0 + elif is_candidate; then + gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC + else + exit 5 # OCF_ERR_INSTALLED (vital component missing) + fi +} + +stop_action() { + # We can't really "stop" being a master. + # TODO: investigate whether a fake approach will do. + exit 1 # OCF_ERR_GENERIC +} + +recover_action() { + if is_master; then + gnt-cluster redist-conf || exit 1 # OCF_ERR_GENERIC + elif is_candidate; then + gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC + else + exit 5 # OCF_ERR_INSTALLED (vital component missing) + fi +} + +monitor_action() { + # monitor should exit: + # 7 if the resource is not running + # 1 if it failed + # 0 if it's running + if is_master; then + exit 0 + elif is_candidate; then + exit 7 # OCF_NOT_RUNNING + else + exit 5 # OCF_ERR_INSTALLED (vital component missing) + fi +} + +return_meta() { +cat < + + +0.1 + +OCF script to manage the ganeti master role in a cluster. + +Can be used to failover the ganeti master between master candidate nodes. + +Manages the ganeti cluster master + + + + + + + + + + + +END +exit 0 +} + +case "$1" in + # Mandatory OCF commands + start) + start_action + ;; + stop) + stop_action + ;; + monitor) + monitor_action + ;; + meta-data) + return_meta + ;; + # Optional OCF commands + recover) + recover_action + ;; + reload) + # The ganeti master role has no "configuration" that is reloadable on + # the pacemaker side. We declare the operation anyway to make sure + # pacemaker doesn't decide to stop and start the service needlessly. + exit 0 + ;; + promote|demote|migrate_to|migrate_from|validate-all) + # Not implemented (nor declared by meta-data) + exit 3 # OCF_ERR_UNIMPLEMENTED + ;; + *) + log_success_msg "Usage: $SCRIPTNAME {start|stop|monitor|meta-data|recover|reload}" + exit 1 + ;; +esac + +exit 0 -- GitLab