[PATCHES] make ctdb runnable in non-FHS installs
Michael Adam
obnox at samba.org
Tue Jun 7 23:30:02 UTC 2016
Hi,
While debugging an issue with ctdb, I thought (again)
it would be convenient to be able to run ctdb(d) in
an install that is not conforming to FHS.
We do already have ctdbd_wrapper to call the daemon,
but several places in event scripts and ctdbd_wrapper
itself directly call ctdbd. So this assumes that ctdb
is in the patch and is to be called without options.
Hence running from a non-fhs install-prefix does not
work at all.
This patch introduces ctdb_wrapper (like ctdbdb_wrapper)
but for the ctdb tool and much simpler, and it changes
all important places (event scripts and ctdbd_wrapper) to
call ctdb_wrapper instead of calling ctdb direclty.
So this patchset lets me successfully start and manage
a ctdb cluster from a non-FHS location.
Review appreciated!
Cheers - Michael
-------------- next part --------------
From 9629849b343bcb9663266065f493a5f2ec6b5133 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 7 Jun 2016 07:36:26 +0000
Subject: [PATCH 1/4] ctdb: add ctdb_wrapper to call ctdb for non-standard
installations
Similar to ctdbd_wrapper for ctdbd, but much more simple
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/config/ctdb_wrapper | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
ctdb/wscript | 12 ++++++++--
2 files changed, 72 insertions(+), 2 deletions(-)
create mode 100755 ctdb/config/ctdb_wrapper
diff --git a/ctdb/config/ctdb_wrapper b/ctdb/config/ctdb_wrapper
new file mode 100755
index 0000000..99aec9f
--- /dev/null
+++ b/ctdb/config/ctdb_wrapper
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# ctdb wrapper - run the right ctdb with the right socket option
+
+############################################################
+
+if [ -z "$CTDB_BASE" ] ; then
+ export CTDB_BASE="/usr/local/etc/ctdb"
+fi
+
+. "${CTDB_BASE}/functions"
+loadconfig "ctdb"
+
+[ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
+
+ctdb="${CTDB:-/usr/local/bin/ctdb}"
+
+build_ctdb_options ()
+{
+ ctdb_options=""
+
+ maybe_set ()
+ {
+ # If the given variable isn't set then do nothing
+ [ -n "$2" ] || return
+ # If a required value for the variable and it doesn't match,
+ # then do nothing
+ [ -z "$3" -o "$3" = "$2" ] || return
+
+ val="'$2'"
+ case "$1" in
+ --*) sep="=" ;;
+ -*) sep=" " ;;
+ esac
+ # For these options we're only passing a value-less flag.
+ if [ -n "$3" ] ; then
+ val=""
+ sep=""
+ fi
+
+ ctdb_options="${ctdb_options}${ctdb_options:+ }${1}${sep}${val}"
+ }
+
+ # build up ctdb_options variable from optional parameters
+ maybe_set "--socket" "$CTDB_SOCKET"
+}
+
+############################################################
+
+build_ctdb_options
+
+if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
+ if [ "$CTDB_VALGRIND" = "yes" ] ; then
+ ctdb="valgrind -q --log-file=/usr/local/var/log/ctdb_valgrind ${ctdb}"
+ else
+ ctdb="${CTDB_VALGRIND} ${ctdb}"
+ fi
+ ctdb_options="${ctdb_options} --valgrinding"
+fi
+
+eval "$ctdb" "$ctdb_options" "$@"
+
diff --git a/ctdb/wscript b/ctdb/wscript
index 744ba96..233bb2b 100755
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -513,9 +513,10 @@ def build(bld):
sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g' % (bld.env.CTDB_RUNDIR)
sed_expr5 = 's|/usr/local/sbin|%s|g' % (bld.env.SBINDIR)
sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g' % (bld.env.CTDB_HELPER_BINDIR)
- sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
+ sed_expr7 = 's|/usr/local/bin|%s|g' % (bld.env.BINDIR)
+ sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
(sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
- sed_expr6)
+ sed_expr6, sed_expr7)
for f in manpages:
x = '%s.xml' % (f)
@@ -571,6 +572,13 @@ def build(bld):
bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
destname='ctdbd_wrapper', chmod=0755)
+ bld.SAMBA_GENERATOR('ctdb-wrapper',
+ source='config/ctdb_wrapper',
+ target='ctdb_wrapper',
+ rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
+ bld.INSTALL_FILES('${BINDIR}', 'ctdb_wrapper',
+ destname='ctdb_wrapper', chmod=0755)
+
def SUBDIR_MODE_callback(arg, dirname, fnames):
for f in fnames:
fl = os.path.join(dirname, f)
--
2.5.5
From 65bc0614b13236e127e793534512402440b4e4cf Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 7 Jun 2016 23:41:49 +0200
Subject: [PATCH 2/4] ctdb: set the path to ctdb_wrapper in 'functions'
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/config/functions | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ctdb/config/functions b/ctdb/config/functions
index 33efa51..4b08ff8 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -10,6 +10,8 @@ fi
CTDB_VARDIR="/usr/local/var/lib/ctdb"
ctdb_rundir="/usr/local/var/run/ctdb"
+CTDB_WRAPPER="${CTDB_WRAPPER:-/usr/local/bin/ctdb_wrapper}"
+
# Only (and always) override these variables in test code
if [ -z "$CTDB_SCRIPT_VARDIR" ] ; then
--
2.5.5
From cdd0afaf3f2b754112e9df41eac00c14a23a341b Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 7 Jun 2016 17:25:40 +0200
Subject: [PATCH 3/4] ctdb: let the event scripts call ctdb_wrapper from the
install
Up to now, the event scripts had been using "ctdb"
which may not be found in a non-FHS install. And
it may not have honoured the configured ctdb socket.
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/config/events.d/00.ctdb | 4 +++-
ctdb/config/events.d/01.reclock | 4 +++-
ctdb/config/events.d/10.external | 6 ++++--
ctdb/config/events.d/13.per_ip_routing | 4 +++-
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb
index 3bc20d7..ae4024b 100755
--- a/ctdb/config/events.d/00.ctdb
+++ b/ctdb/config/events.d/00.ctdb
@@ -9,6 +9,8 @@
. $CTDB_BASE/functions
loadconfig
+ctdb="${CTDB_WRAPPER:-ctdb}"
+
ctdb_setup_service_state_dir "ctdb"
############################################################
@@ -107,7 +109,7 @@ set_ctdb_variables ()
while read v; do
varname="${v#CTDB_SET_}"
value=$(eval echo "\$$v")
- if ctdb setvar $varname $value ; then
+ if eval "$ctdb setvar $varname $value" ; then
echo "Set $varname to $value"
else
echo "Invalid configuration: CTDB_SET_${varname}=${value}"
diff --git a/ctdb/config/events.d/01.reclock b/ctdb/config/events.d/01.reclock
index e2d4d12..0c3f7a7 100755
--- a/ctdb/config/events.d/01.reclock
+++ b/ctdb/config/events.d/01.reclock
@@ -7,6 +7,8 @@
. $CTDB_BASE/functions
loadconfig
+ctdb="${CTDB_WRAPPER:-ctdb}"
+
# If CTDB_RECOVERY_LOCK specifies a helper then exit because this
# script can't do anything useful.
case "$CTDB_RECOVERY_LOCK" in
@@ -41,7 +43,7 @@ case "$1" in
echo "Reclock file \"$CTDB_RECOVERY_LOCK\" can not be accessed. Shutting down."
df
sleep 1
- ctdb shutdown
+ eval "$ctdb shutdown"
fi
ctdb_check_counter "error" -gt 3
diff --git a/ctdb/config/events.d/10.external b/ctdb/config/events.d/10.external
index 3fcb0e1..dd35483 100644
--- a/ctdb/config/events.d/10.external
+++ b/ctdb/config/events.d/10.external
@@ -13,6 +13,8 @@
. $CTDB_BASE/functions
loadconfig
+ctdb="${CTDB_WRAPPER:-ctdb}"
+
if [ -z "$CTDB_PUBLIC_ADDRESSES" ] ; then
exit 0
fi
@@ -28,12 +30,12 @@ takeover_assigned_ips ()
{
ctdb_get_pnn
- ctdb -X ip |
+ eval "$ctdb -X ip" |
awk -F'|' '{print $2}' |
while read ip ; do
if [ -n "$(ip_maskbits_iface $ip)" ] ; then
echo "Assigning $ip to this node ($pnn)"
- ctdb moveip "$ip" "$pnn"
+ eval "$ctdb moveip \"$ip\" \"$pnn\""
fi
done
}
diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing
index 56dfc34..056b578 100755
--- a/ctdb/config/events.d/13.per_ip_routing
+++ b/ctdb/config/events.d/13.per_ip_routing
@@ -6,6 +6,8 @@
. $CTDB_BASE/functions
loadconfig
+ctdb="${CTDB_WRAPPER:-ctdb}"
+
service_name=per_ip_routing
# Do nothing if unconfigured
@@ -292,7 +294,7 @@ flush_rules_and_routes ()
# routes.
add_missing_routes ()
{
- ctdb ip -v -X | {
+ eval "$ctdb ip -v -X" | {
read _x # skip header line
# Read the rest of the lines. We're only interested in the
--
2.5.5
From 89caab6848f4bbf080a54f04739779c02775e90c Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 7 Jun 2016 07:44:53 +0000
Subject: [PATCH 4/4] ctdb: let ctdbd_wrapper call ctdb_wrapper properly
This makes ctdbd_wrapper usable in non-standard installs.
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/config/ctdbd_wrapper | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper
index b1f71c3..26f6ba2 100755
--- a/ctdb/config/ctdbd_wrapper
+++ b/ctdb/config/ctdbd_wrapper
@@ -25,6 +25,7 @@ loadconfig "ctdb"
[ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
+ctdb="${CTDB_WRAPPER:-/usr/local/bin/ctdb_wrapper}"
############################################################
@@ -256,7 +257,7 @@ start()
return 1
fi
- if ctdb runstate first_recovery startup running >/dev/null 2>&1 ; then
+ if eval "$ctdb runstate first_recovery startup running" >/dev/null 2>&1 ; then
return 0
fi
fi
@@ -278,7 +279,7 @@ stop()
return 0
fi
- ctdb shutdown
+ eval "$ctdb shutdown"
# Wait for remaining CTDB processes to exit...
_timeout=${CTDB_SHUTDOWN_TIMEOUT:-30}
--
2.5.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160608/d8d26b2b/signature.sig>
More information about the samba-technical
mailing list