Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Redis Resource Agent #37

Closed
wants to merge 4 commits into from

5 participants

@coredump

Provides a Resource Agent to manage master-slave sets of Redis servers. Depends on start-stop-daemon, unfortunately, since redis doesn't support dropping privileges by itself.

@fghaas fghaas commented on the diff
heartbeat/redis
@@ -0,0 +1,545 @@
+#!/bin/bash
@fghaas Owner
fghaas added a note

You can switch this to /bin/sh; AFAICT the RA doesn't contain any bashisms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((42 lines not shown))
+
+#######################################################################
+PATH=$PATH:/usr/local/bin:/usr/local/sbin
+
+# Fill in some defaults if no values are specified
+OCF_RESKEY_binary_default=redis-server
+OCF_RESKEY_client_binary_default=redis-cli
+OCF_RESKEY_config_default=/etc/redis/redis.conf
+OCF_RESKEY_port_default=6379
+OCF_RESKEY_user_default=redis
+OCF_RESKEY_group_default=redis
+OCF_RESKEY_log_default=/var/log/redis/redis-server.log
+OCF_RESKEY_pid_default=/var/run/redis.pid
+
+: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
+REDIS_SERVER_NAME=${OCF_RESKEY_binary}
@fghaas Owner
fghaas added a note

Um. How is $REDIS_SERVER_NAME shorter than $OCF_RESKEY_binary? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((107 lines not shown))
+</parameter>
+
+<parameter name="client_binary" unique="0" required="0">
+<longdesc lang="en">
+Name of the redis client binary. Use an absolute path if the binary is not resolvable via \$PATH
+</longdesc>
+<shortdesc lang="en">redis client binary</shortdesc>
+<content type="string" default="${OCF_RESKEY_client_binary_default}" />
+</parameter>
+
+<parameter name="port" unique="0" required="0">
+<longdesc lang="en">
+Port where the redis server is listening
+</longdesc>
+<shortdesc lang="en">redis port</shortdesc>
+<content type="string" default="${OCF_RESKEY_port_default}" />
@fghaas Owner
fghaas added a note

Integer, not string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((269 lines not shown))
+
+# Functions invoked by resource manager actions
+
+redis_validate() {
+ check_binary $OCF_RESKEY_binary
+ check_binary $OCF_RESKEY_client_binary
+ check_binary start-stop-daemon
+
+ if [ ! -f $OCF_RESKEY_config ]; then
+ ocf_log err "Config $OCF_RESKEY_config doesn't exist";
+ return $OCF_ERR_INSTALLED;
+ fi
+
+ getent passwd $OCF_RESKEY_user >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ ocf_log err "User $OCF_RESKEY_user doesn't exit";
@fghaas Owner
fghaas added a note

"exist"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((328 lines not shown))
+ redis_status
+ rc=$?
+
+ if [ $rc -eq $OCF_RUNNING_MASTER -o $rc -eq $OCF_SUCCESS ]; then
+ ocf_log info "$REDIS_SERVER_NAME is already running"
+ return $OCF_SUCCESS
+ fi
+
+ touch $OCF_RESKEY_log
+ chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_log
+ chmod 0640 $OCF_RESKEY_log
+
+ touch $OCF_RESKEY_pid
+ chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_pid
+
+ start-stop-daemon --start --quiet --umask 007 --pidfile $OCF_RESKEY_pid --make-pidfile --chuid $OCF_RESKEY_user:$OCF_RESKEY_group --exec $OCF_RESKEY_binary -- $OCF_RESKEY_config
@fghaas Owner
fghaas added a note

I (still) hate this, as this makes the RA Debian/Ubuntu specific. JFTR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((463 lines not shown))
+ fi
+
+ type_op="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
+ ocf_log debug "Received $type_op notification."
+
+ case "$type_op" in
+ 'pre-promote')
+ # A node is about to being promoted to master.
+ master_host=$(echo $OCF_RESKEY_CRM_meta_notify_promote_uname | tr -d " ")
+ if [ -z "$master_host" ]; then
+ ocf_log err "Unable to determine host to be promoted!"
+ return $OCF_ERR_GENERIC
+ fi
+
+ if [ $master_host = $(uname -n) ]; then
+ ocf_log info "We are about to being promoted."
@fghaas Owner
fghaas added a note

Grammar error, should be "about to be".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((468 lines not shown))
+ case "$type_op" in
+ 'pre-promote')
+ # A node is about to being promoted to master.
+ master_host=$(echo $OCF_RESKEY_CRM_meta_notify_promote_uname | tr -d " ")
+ if [ -z "$master_host" ]; then
+ ocf_log err "Unable to determine host to be promoted!"
+ return $OCF_ERR_GENERIC
+ fi
+
+ if [ $master_host = $(uname -n) ]; then
+ ocf_log info "We are about to being promoted."
+ return $OCF_SUCCESS
+ fi
+
+ ocf_log info "Becoming a slave of $master_host"
+ set_master $master_host
@fghaas Owner
fghaas added a note

Are you sure this has to happen in the pre-promote notification? One would casually expect this in post-promote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fghaas fghaas commented on the diff
heartbeat/redis
((484 lines not shown))
+ if [ $? -ne 0 ]; then
+ return $OCF_ERR_GENERIC
+ else
+ return $OCF_SUCCESS
+ fi
+ ;;
+ 'pre-demote')
+ # A master is about to being demoted.
+ demote_host=$(echo $OCF_RESKEY_CRM_meta_notify_demote_uname | tr -d " ")
+ if [ -z "$demote_host" ]; then
+ ocf_log err "Unable to determine host to be demoted!"
+ return $OCF_ERR_GENERIC
+ fi
+
+ if [ $demote_host = $(uname -n) ]; then
+ ocf_log info "We are about to being demoted."
@fghaas Owner
fghaas added a note

Same grammar error as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dmuhamedagic

Any news here? The dependency on debian specific commands (start-stop-daemon) is quite bad though. Any chance of replacing it? After all, I guess that redis is run on other platforms/distributions too.

@fghaas
Owner

Anyone up for writing an ocf_start_daemon and ocf_stop_daemon function? This RA wants to use start-stop-daemon which is Debian and Ubuntu specific. We have one other that uses startproc which is only on SUSE, and Red Hat has its own way of starting daemons. Suggestions?

@dmuhamedagic
Owner

I have no objections to implementing such functions, but it's probably not going to be trivial to implement properly given the number of different options supported by startproc/start-stop-daemon. Is there a way to implement redis without start-stop-daemon?

@dmuhamedagic

@coredump, is it possible to run redis without debian-specific stuff?

@pemer

Hi Guys,

ic have re-written the redis resource agent, you can download my fork:
https://github.com/afdata/resource-agents
Any kind of feedback are welcome.

regards

Patrick

@dmuhamedagic

This is the second rewrite, if I'm not mistaken. And this one still uses the debian-specific start-stop-daemon, which is the main obstacle for pulling the agent into the repository. @afdata, did you take a look at the comments?

@pemer

no, I have not read.
but this is a good issue in my fork!

thx you
regards Patrick

@krig

This request should be closed as it is superseded by the request in #212.

@dmuhamedagic

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 30, 2011
  1. @coredump

    Adds the RA for the redis service, based on that of mysql. Supports m…

    Martin Walter authored coredump committed
    …aster/slave configurations of a depth of 1.
  2. @coredump
  3. @coredump
  4. @coredump
This page is out of date. Refresh to see the latest.
Showing with 545 additions and 0 deletions.
  1. +545 −0 heartbeat/redis
View
545 heartbeat/redis
@@ -0,0 +1,545 @@
+#!/bin/bash
@fghaas Owner
fghaas added a note

You can switch this to /bin/sh; AFAICT the RA doesn't contain any bashisms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+#
+#
+# redis
+#
+# Description: Manages redis as Linux-HA resource
+#
+# Authors: Alan Robertson,
+# Jakub Janczak,
+# Andrew Beekhof,
+# Sebastian Reitenbach,
+# Narayan Newton,
+# Marian Marinov,
+# Florian Haas: MySQL script
+# Martin Walter: rewrite as redis
+# Jose Junior: tweaks to the redis version
+#
+# Support: linux-ha@lists.linux-ha.org
+# License: GNU General Public License (GPL)
+#
+# (c) 2002-2005 International Business Machines, Inc.
+# 2005-2010 Linux-HA contributors
+#
+# An example usage in /etc/ha.d/haresources:
+# node1 10.0.0.170 redis
+#
+# See usage() function below for more details...
+#
+# OCF instance parameters:
+# OCF_RESKEY_binary
+# OCF_RESKEY_client_binary
+# OCF_RESKEY_config
+# OCF_RESKEY_user
+# OCF_RESKEY_group
+# OCF_RESKEY_log
+# OCF_RESKEY_pid
+#######################################################################
+# Initialization:
+
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
+
+#######################################################################
+PATH=$PATH:/usr/local/bin:/usr/local/sbin
+
+# Fill in some defaults if no values are specified
+OCF_RESKEY_binary_default=redis-server
+OCF_RESKEY_client_binary_default=redis-cli
+OCF_RESKEY_config_default=/etc/redis/redis.conf
+OCF_RESKEY_port_default=6379
+OCF_RESKEY_user_default=redis
+OCF_RESKEY_group_default=redis
+OCF_RESKEY_log_default=/var/log/redis/redis-server.log
+OCF_RESKEY_pid_default=/var/run/redis.pid
+
+: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
+REDIS_SERVER_NAME=${OCF_RESKEY_binary}
@fghaas Owner
fghaas added a note

Um. How is $REDIS_SERVER_NAME shorter than $OCF_RESKEY_binary? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+: ${OCF_RESKEY_client_binary=${OCF_RESKEY_client_binary_default}}
+: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}
+: ${OCF_RESKEY_port=${OCF_RESKEY_port_default}}
+: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
+: ${OCF_RESKEY_group=${OCF_RESKEY_group_default}}
+: ${OCF_RESKEY_log=${OCF_RESKEY_log_default}}
+: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
+
+#######################################################################
+
+usage() {
+ cat <<UEND
+ usage: $0 (start|stop|validate-all|meta-data|monitor|promote|demote|notify)
+
+ $0 manages redis as an HA resource.
+
+ The 'start' operation starts redis.
+ The 'stop' operation stops redis.
+ The 'status' operation reports whether redis is running
+ The 'monitor' operation reports whether redis seems to be working
+ The 'promote' operation makes this redis instance run as master
+ The 'demote' operation makes this redis instance run as slave
+ The 'validate-all' operation reports whether the parameters are valid
+
+UEND
+}
+
+meta_data() {
+ cat <<END
+<?xml version="1.0"?>
+<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
+<resource-agent name="redis">
+<version>1.0</version>
+
+<longdesc lang="en">
+Resource script for redis.
+It manages a redis instance as an HA resource.
+</longdesc>
+<shortdesc lang="en">Manages a redis instance</shortdesc>
+
+<parameters>
+
+<parameter name="binary" unique="0" required="0">
+<longdesc lang="en">
+Name of the redis server binary. Use an absolute path if the binary is not resolvable via \$PATH
+</longdesc>
+<shortdesc lang="en">redis binary</shortdesc>
+<content type="string" default="${OCF_RESKEY_binary_default}" />
+</parameter>
+
+<parameter name="client_binary" unique="0" required="0">
+<longdesc lang="en">
+Name of the redis client binary. Use an absolute path if the binary is not resolvable via \$PATH
+</longdesc>
+<shortdesc lang="en">redis client binary</shortdesc>
+<content type="string" default="${OCF_RESKEY_client_binary_default}" />
+</parameter>
+
+<parameter name="port" unique="0" required="0">
+<longdesc lang="en">
+Port where the redis server is listening
+</longdesc>
+<shortdesc lang="en">redis port</shortdesc>
+<content type="string" default="${OCF_RESKEY_port_default}" />
@fghaas Owner
fghaas added a note

Integer, not string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+</parameter>
+
+<parameter name="config" unique="0" required="0">
+<longdesc lang="en">
+Location of the Redis configuration file
+</longdesc>
+<shortdesc lang="en">redis config</shortdesc>
+<content type="string" default="${OCF_RESKEY_config_default}" />
+</parameter>
+
+<parameter name="user" unique="0" required="0">
+<longdesc lang="en">
+User running redis
+</longdesc>
+<shortdesc lang="en">redis user</shortdesc>
+<content type="string" default="${OCF_RESKEY_user_default}" />
+</parameter>
+
+<parameter name="group" unique="0" required="0">
+<longdesc lang="en">
+Group running redis (for logfile and directory permissions)
+</longdesc>
+<shortdesc lang="en">redis group</shortdesc>
+<content type="string" default="${OCF_RESKEY_group_default}"/>
+</parameter>
+
+<parameter name="log" unique="0" required="0">
+<longdesc lang="en">
+The logfile to be used for redis-server.
+</longdesc>
+<shortdesc lang="en">$REDIS_SERVER_NAME log file</shortdesc>
+<content type="string" default="${OCF_RESKEY_log_default}"/>
+</parameter>
+
+<parameter name="pid" unique="0" required="0">
+<longdesc lang="en">
+The pidfile to be used for redis-server.
+</longdesc>
+<shortdesc lang="en">$REDIS_SERVER_NAME pid file</shortdesc>
+<content type="string" default="${OCF_RESKEY_pid_default}"/>
+</parameter>
+
+</parameters>
+
+<actions>
+<action name="start" timeout="120" />
+<action name="stop" timeout="120" />
+<action name="status" timeout="60" />
+<action name="monitor" depth="0" timeout="30" interval="20" />
+<action name="monitor" role="Master" depth="0" timeout="30" interval="10" />
+<action name="monitor" role="Slave" depth="0" timeout="30" interval="30" />
+<action name="promote" timeout="120" />
+<action name="demote" timeout="120" />
+<action name="notify" timeout="90" />
+<action name="validate-all" timeout="5" />
+<action name="meta-data" timeout="5" />
+</actions>
+</resource-agent>
+END
+}
+
+#######################################################################
+# Convenience variables
+
+CRM_MASTER="${HA_SBIN_DIR}/crm_master -l reboot "
+
+#######################################################################
+
+# Convenience functions
+
+read_ms_status() {
+ local tmp
+ local has_slave_role
+ local master_host
+ local master_host_value
+
+ tmp=$(mktemp -p $HA_RSCTMP)
+ $OCF_RESKEY_client_binary info >$tmp
+ if [ $? -ne 0 ]; then
+ ocf_log info "Could not determine master/slave status";
+ rm -f $tmp
+ return $OCF_ERR_GENERIC;
+ fi
+
+ grep -e "role:slave" $tmp >/dev/null 2>&1
+ has_slave_role=$?
+
+ master_host_value=""
+ master_host=$(grep -e "master_host:" $tmp)
+ if [ $? -eq 0 ]; then
+ master_host_value=$(echo $master_host | cut -d':' -f2 | tr -d " ")
+ fi
+
+ rm -f $tmp
+
+ if [ $has_slave_role -eq 0 -a "x$master_host_value" != "x" ]; then
+ ocf_log info "$REDIS_SERVER_NAME is running (as slave)";
+ return $OCF_SUCCESS;
+ else
+ ocf_log info "$REDIS_SERVER_NAME is running (as master)";
+ return $OCF_RUNNING_MASTER;
+ fi
+}
+
+read_pid() {
+ pid=""
+
+ if [ -e $OCF_RESKEY_pid ]; then
+ pid=$(cat $OCF_RESKEY_pid);
+ fi
+
+ if [ $? -ne 0 -o "x$pid" = "x" ]; then
+ pid=$(pidof -s $OCF_RESKEY_binary)
+ fi
+
+ if [ $? -ne 0 -o "x$pid" = "x" ]; then
+ ocf_log info "Could not read PID, $REDIS_SERVER_NAME is not running";
+ return $OCF_NOT_RUNNING
+ else
+ ocf_log info "$REDIS_SERVER_NAME is running (PID $pid)";
+ return $OCF_SUCCESS
+ fi
+}
+
+remove_pid() {
+ ocf_log debug "Removing PID file $OCF_RESKEY_pid"
+ rm -f $OCF_RESKEY_pid
+}
+
+set_master() {
+ local master_host=$1
+
+ ocf_log info "Set $REDIS_SERVER_NAME to be a slave of $master_host";
+ ocf_run $OCF_RESKEY_client_binary slaveof $master_host $OCF_RESKEY_port
+ return $?
+}
+
+unset_master() {
+ local rc
+
+ ocf_log info "Set $REDIS_SERVER_NAME to become a slave of no one";
+ ocf_run $OCF_RESKEY_client_binary slaveof no one
+ return $?
+}
+
+#######################################################################
+
+# Functions invoked by resource manager actions
+
+redis_validate() {
+ check_binary $OCF_RESKEY_binary
+ check_binary $OCF_RESKEY_client_binary
+ check_binary start-stop-daemon
+
+ if [ ! -f $OCF_RESKEY_config ]; then
+ ocf_log err "Config $OCF_RESKEY_config doesn't exist";
+ return $OCF_ERR_INSTALLED;
+ fi
+
+ getent passwd $OCF_RESKEY_user >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ ocf_log err "User $OCF_RESKEY_user doesn't exit";
@fghaas Owner
fghaas added a note

"exist"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return $OCF_ERR_INSTALLED;
+ fi
+
+ getent group $OCF_RESKEY_group >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ ocf_log err "Group $OCF_RESKEY_group doesn't exist";
+ return $OCF_ERR_INSTALLED;
+ fi
+
+ true
+}
+
+redis_status() {
+ local rc
+
+ read_pid
+ rc=$?
+
+ if [ $rc -ne $OCF_SUCCESS ]; then
+ ocf_log err "Removing PID"
+ remove_pid
+ return $rc
+ fi
+
+ read_ms_status
+ rc=$?
+ if ocf_is_ms; then
+ return $rc
+ else
+ if [ $rc -eq $OCF_SUCCESS -o $rc -eq $OCF_RUNNING_MASTER ]; then
+ ocf_log info "Redis is running"
+ return $OCF_SUCCESS
+ else
+ return $OCF_ERR_GENERIC
+ fi
+ fi
+}
+
+redis_start() {
+
+ local master_host
+ local rc
+
+ redis_status
+ rc=$?
+
+ if [ $rc -eq $OCF_RUNNING_MASTER -o $rc -eq $OCF_SUCCESS ]; then
+ ocf_log info "$REDIS_SERVER_NAME is already running"
+ return $OCF_SUCCESS
+ fi
+
+ touch $OCF_RESKEY_log
+ chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_log
+ chmod 0640 $OCF_RESKEY_log
+
+ touch $OCF_RESKEY_pid
+ chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_pid
+
+ start-stop-daemon --start --quiet --umask 007 --pidfile $OCF_RESKEY_pid --make-pidfile --chuid $OCF_RESKEY_user:$OCF_RESKEY_group --exec $OCF_RESKEY_binary -- $OCF_RESKEY_config
@fghaas Owner
fghaas added a note

I (still) hate this, as this makes the RA Debian/Ubuntu specific. JFTR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ rc=$?
+
+ if [ $rc -ne 0 ]; then
+ ocf_log err "$OCF_RESKEY_binary start command failed: $rc"
+ return $OCF_NOT_RUNNING
+ fi
+
+ if ocf_is_ms; then
+ # Now, let's see whether there is a master. We might be a new
+ # node that is just joining the cluster, and the CRM may have
+ # promoted a master before.
+ master_host=$(echo $OCF_RESKEY_CRM_meta_notify_master_uname | tr -d " ")
+ if [ ! -z "$master_host" -a "$master_host" != $(uname -n) ]; then
+ ocf_log info "Changing redis configuration to replicate from host: $master_host"
+ while true; do
+ $OCF_RESKEY_client_binary info |grep 'loading:0'
+ if [ $? -eq 0 ]; then
+ break
+ else
+ ocf_log err "Redis still loading data, giving it a second to finish"
+ sleep 1
+ fi
+ done
+ set_master $master_host
+ fi
+
+ # We also need to set a master preference, otherwise Pacemaker
+ # won't ever promote us in the absence of any explicit
+ # preference set by the administrator. We choose a low
+ # greater-than-zero preference.
+ $CRM_MASTER -v 1
+ fi
+
+ ocf_log info "$REDIS_SERVER_NAME started"
+ return $OCF_SUCCESS
+}
+
+redis_stop() {
+ local rc
+
+ if ocf_is_ms; then
+ # clear preference for becoming master
+ $CRM_MASTER -D
+ fi
+
+ redis_status
+ rc=$?
+
+ if [ $rc -ne $OCF_RUNNING_MASTER -a $rc -ne $OCF_SUCCESS ]; then
+ ocf_log info "$REDIS_SERVER_NAME is not running";
+ return $OCF_SUCCESS
+ fi
+
+ start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $OCF_RESKEY_pid --exec $( which $OCF_RESKEY_binary)
+ rc=$?
+
+ if [ $rc -ne 0 ]; then
+ ocf_log err "$OCF_RESKEY_binary stop command failed: $rc"
+ return $OCF_ERR_GENERIC
+ fi
+
+ ocf_log info "$REDIS_SERVER_NAME stopped";
+ remove_pid
+ return $OCF_SUCCESS
+}
+
+redis_promote() {
+ local rc
+
+ redis_status
+ rc=$?
+
+ if [ $rc -ne $OCF_RUNNING_MASTER -a $rc -ne $OCF_SUCCESS ]; then
+ return $OCF_NOT_RUNNING
+ fi
+
+ # Existing master gets a higher-than-default master preference, so
+ # the cluster manager does not shuffle the master role around
+ # unnecessarily
+ $CRM_MASTER -v 10000
+
+ return $OCF_SUCCESS
+}
+
+redis_demote() {
+ local rc
+
+ redis_status
+ rc=$?
+
+ if [ $rc -ne $OCF_RUNNING_MASTER -a $rc -ne $OCF_SUCCESS ]; then
+ return $OCF_NOT_RUNNING
+ fi
+
+ # Return master preference to default, so the cluster manager gets
+ # a chance to select a new master
+ $CRM_MASTER -v 1
+
+ return $OCF_SUCCESS
+}
+
+redis_notify() {
+ local rc
+
+ local master_host
+ local type_op
+
+ redis_status
+ rc=$?
+
+ if [ $rc -ne $OCF_RUNNING_MASTER -a $rc -ne $OCF_SUCCESS ]; then
+ return $OCF_NOT_RUNNING
+ fi
+
+ # If not configured as a Stateful resource, we make no sense of
+ # notifications.
+ if ! ocf_is_ms; then
+ ocf_log info "This agent makes no use of notifications unless running in master/slave mode."
+ return $OCF_SUCCESS
+ fi
+
+ type_op="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
+ ocf_log debug "Received $type_op notification."
+
+ case "$type_op" in
+ 'pre-promote')
+ # A node is about to being promoted to master.
+ master_host=$(echo $OCF_RESKEY_CRM_meta_notify_promote_uname | tr -d " ")
+ if [ -z "$master_host" ]; then
+ ocf_log err "Unable to determine host to be promoted!"
+ return $OCF_ERR_GENERIC
+ fi
+
+ if [ $master_host = $(uname -n) ]; then
+ ocf_log info "We are about to being promoted."
@fghaas Owner
fghaas added a note

Grammar error, should be "about to be".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return $OCF_SUCCESS
+ fi
+
+ ocf_log info "Becoming a slave of $master_host"
+ set_master $master_host
@fghaas Owner
fghaas added a note

Are you sure this has to happen in the pre-promote notification? One would casually expect this in post-promote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if [ $? -ne 0 ]; then
+ return $OCF_ERR_GENERIC
+ else
+ return $OCF_SUCCESS
+ fi
+ ;;
+ 'pre-demote')
+ # A master is about to being demoted.
+ demote_host=$(echo $OCF_RESKEY_CRM_meta_notify_demote_uname | tr -d " ")
+ if [ -z "$demote_host" ]; then
+ ocf_log err "Unable to determine host to be demoted!"
+ return $OCF_ERR_GENERIC
+ fi
+
+ if [ $demote_host = $(uname -n) ]; then
+ ocf_log info "We are about to being demoted."
@fghaas Owner
fghaas added a note

Same grammar error as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return $OCF_SUCCESS
+ fi
+
+ ocf_log info "Deslaving from $demote_host."
+ unset_master
+ return $OCF_SUCCESS
+ ;;
+ *)
+ return $OCF_SUCCESS
+ ;;
+ esac
+}
+
+#######################################################################
+
+# Make sure meta-data and usage always succeed
+case $__OCF_ACTION in
+meta-data) meta_data
+ exit $OCF_SUCCESS
+ ;;
+usage|help) usage
+ exit $OCF_SUCCESS
+ ;;
+esac
+
+# Anything other than meta-data and usage must pass validation
+redis_validate || exit $?
+
+# Translate each action into the appropriate function call
+case $__OCF_ACTION in
+start) redis_start;;
+stop) redis_stop;;
+status|monitor) redis_status;;
+promote) redis_promote;;
+demote) redis_demote;;
+notify) redis_notify;;
+validate-all) ;;
+*) usage
+ exit $OCF_ERR_UNIMPLEMENTED
+ ;;
+esac
+rc=$?
+
+# The resource agent may optionally log a debug message
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc"
+exit $rc
Something went wrong with that request. Please try again.