Commit aa75500a authored by Guido Trotter's avatar Guido Trotter

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 32a569fe
......@@ -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
......
......@@ -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
......
......@@ -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"
......
#!/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 <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="ganeti-master-role" version="0.1">
<version>0.1</version>
<longdesc lang="en">
OCF script to manage the ganeti master role in a cluster.
Can be used to failover the ganeti master between master candidate nodes.
</longdesc>
<shortdesc lang="en">Manages the ganeti cluster master</shortdesc>
<parameters/>
<actions>
<action name="start" timeout="300s" />
<action name="stop" timeout="50s" />
<action name="monitor" depth="0" timeout="10s" interval="30s" />
<action name="meta-data" timeout="5s" />
<action name="recover" timeout="20s" />
<action name="reload" timeout="5s" />
</actions>
</resource-agent>
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment