Redis Resource Agent #37

Closed
wants to merge 4 commits into
from

Projects

None yet

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 Nov 30, 2011
heartbeat/redis
@@ -0,0 +1,545 @@
+#!/bin/bash
@fghaas
fghaas Nov 30, 2011 Member

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

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+
+#######################################################################
+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
fghaas Nov 30, 2011 Member

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

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+</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
fghaas Nov 30, 2011 Member

Integer, not string.

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+
+# 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
fghaas Nov 30, 2011 Member

"exist"

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+ 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
fghaas Nov 30, 2011 Member

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

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+ 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
fghaas Nov 30, 2011 Member

Grammar error, should be "about to be".

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+ 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
fghaas Nov 30, 2011 Member

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

@fghaas fghaas commented on the diff Nov 30, 2011
heartbeat/redis
+ 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
fghaas Nov 30, 2011 Member

Same grammar error as above.

@dmuhamedagic
Contributor

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
Member
fghaas commented Feb 17, 2012

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
Contributor

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
Contributor

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

@pemer
Contributor
pemer commented Jan 26, 2013

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
Contributor

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
Contributor
pemer commented Feb 2, 2013

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

thx you
regards Patrick

@krig
Member
krig commented Jan 8, 2015

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

@dmuhamedagic
Contributor

Closing.

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