[PATCHES] make ctdb runnable in non-FHS installs

Michael Adam obnox at samba.org
Thu Jun 9 15:57:21 UTC 2016


On 2016-06-09 at 07:10 -0500, José A. Rivera wrote:
> On 2016-06-08 09:51, Michael Adam wrote:
> > Attached find the updated patchset that implements
> > the changes from our discussion.
> > 
> > It also covers a few cases of direct use of 'ctdb'
> > that I did not catch before.
> > 
> > But beware that this is not for pushing yet:
> > 
> > This implements the rename of ctdb->ctdb_tool
> > and establishes the former ctdb_wrapper as
> > discussed. While this works nicely from an
> > install, it does (as I feared) put up some
> > problems with selftest, since the 'ctdb' tool
> > is used (verbatim) in the tests. And also,
> > afaict the ctdb wrapper tool is only prepared
> > during 'make install' not during 'make'.
> > 
> > So we have several options out of this:
> > 1) Either refrain from renaming ctdb->ctdb_tool
> >    and keep ctdb_wrapper for a start,
> > 2) or stick with the renaming and rename all
> >    use of 'ctdb' to ctdb_tool in the tests
> > 3) or somehow make sure that ctdb (wrapper)
> >    (and possibly ctdbd_wrapper) are prepared
> >    during make and can be used in the tests.
> > 
> > Not sure. #1 would be the least effort and might
> > be a good start. #2 would be a bigger sweeping
> > rename, and #3 might be conceptually better,
> > but requires some wscript voodoo that at least
> > I'd have to think about for some time.
> > 
> > Opinions?
> > 
> > Cheers - Michael
> 
> #1 seems like a good start. That leading into #3 seems like a good overall
> solution, off-hand.

Thanks!

After a long fruitful IRC discussion with Martin
and Amitay, we are sticking with #1, i.e. not renaming
ctdb and naming the wrapper ctdb. This poses too many
problems.

Instead the updated patchset first makes sure that
the proper ctdb binary can always be found as $CTDB
in the scripts (and is used in the scripts). For the
tests, a simple CTDB=ctdb override did the trick.

Node: I provided patches to make use of $CTDB
instead of verbatim 'ctdb' as one patch per file.
I like this better, but if people insist, we could
also squash those into one big sweeping change patch.

Finally the super simple wrapper is provided
as ctdb_wrapper. This is mainly convenient
when a non-default CTDB_SOCKET is set in the conf file.

Note: instead of doing the maybe_set thing to
turn CTDB_SOCKET into a --socket option, we could
use export CTDB_SOCKET, but I like cmdline options
better and we don't need the export for other purposes.

In the long run we may teach ctdb (and ctdbd) to
properly parse a config file, and then get rid of
the band-aid that ctdb_wrapper is.


This patchset survives autobuild for me.

Cheers - Michael
-------------- next part --------------
From 1728941831345b067130b533ae10330166948911 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:08:35 +0200
Subject: [PATCH 01/16] ctdb: set the path to 'ctdb' in 'functions' in CTDB

Allow this to be overridden from the caller.

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 b2a0735..7032540 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="${CTDB:-/usr/local/bin/ctdb}"
+
 # Only (and always) override these variables in test code
 
 if [ -z "$CTDB_SCRIPT_VARDIR" ] ; then
-- 
2.5.5


From 9fd45426211d682eacffdd662fa00f20e9941304 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:28:36 +0200
Subject: [PATCH 02/16] ctdb: use properly configured ctdb in functions

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/functions | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/ctdb/config/functions b/ctdb/config/functions
index 7032540..e32826d 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -245,7 +245,7 @@ ctdb_get_pnn ()
 {
     _pnn_file="${CTDB_SCRIPT_VARDIR}/my-pnn"
     if [ ! -f "$_pnn_file" ] ; then
-	ctdb pnn | sed -e 's at .*:@@' >"$_pnn_file"
+	$CTDB pnn | sed -e 's at .*:@@' >"$_pnn_file"
     fi
 
     read pnn <"$_pnn_file"
@@ -257,7 +257,7 @@ ctdb_get_ip_address ()
 {
     _ip_addr_file="${CTDB_SCRIPT_VARDIR}/my-ip-address"
     if [ ! -f "$_ip_addr_file" ] ; then
-	ctdb -X nodestatus |
+	$CTDB -X nodestatus |
 	    awk -F '|' 'NR == 2 { print $3 }' >"$_ip_addr_file"
     fi
 
@@ -380,7 +380,7 @@ ctdb_check_tcp_ports()
     fi
 
     for _p ; do  # process each function argument (port)
-	_cmd="ctdb checktcpport $_p"
+	_cmd="$CTDB checktcpport $_p"
 	_out=$($_cmd 2>&1)
 	_ret=$?
 	case "$_ret" in
@@ -402,7 +402,7 @@ ctdb_check_tcp_ports()
 	    *)
 		echo "ERROR: unexpected error running \"ctdb checktcpport\""
 		debug <<EOF
-ctdb checktcpport (exited with $_ret) with output:
+$CTDB checktcpport (exited with $_ret) with output:
 $_out"
 EOF
 		return $_ret
@@ -520,9 +520,9 @@ tickle_tcp_connections ()
 
 	while read dest src; do
 	    echo "Tickle TCP connection $src $dest"
-	    ctdb tickle $src $dest >/dev/null 2>&1 || _failed=true
+	    $CTDB tickle $src $dest >/dev/null 2>&1 || _failed=true
 	    echo "Tickle TCP connection $dest $src"
-	    ctdb tickle $dest $src >/dev/null 2>&1 || _failed=true
+	    $CTDB tickle $dest $src >/dev/null 2>&1 || _failed=true
 	done
 
 	if $_failed ; then
@@ -911,7 +911,7 @@ ctdb_replay_monitor_status ()
 {
     echo "Replaying previous status for this script due to reconfigure..."
     # Leading separator ('|') is missing in some versions...
-    _out=$(ctdb scriptstatus -X | grep -E "^\|?monitor\|${script_name}\|")
+    _out=$($CTDB scriptstatus -X | grep -E "^\|?monitor\|${script_name}\|")
     # Output looks like this:
     # |monitor|60.nfs|1|ERROR|1314764004.030861|1314764004.035514|foo bar|
     # This is the cheapest way of getting fields in the middle.
@@ -1243,7 +1243,7 @@ update_tickles ()
 	ctdb_get_pnn
 
 	# What public IPs do I hold?
-	_ips=$(ctdb -X ip | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}')
+	_ips=$($CTDB -X ip | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}')
 
 	# IPs and port as ss filters
 	_ip_filter=""
@@ -1268,7 +1268,7 @@ update_tickles ()
 	# Record our current tickles in a temporary file
 	_my_tickles="${tickledir}/${_port}.tickles.$$"
 	for _i in $_ips ; do
-		ctdb -X gettickles $_i $_port |
+		$CTDB -X gettickles $_i $_port |
 		awk -F'|' 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }'
 	done |
 	sort >"$_my_tickles"
@@ -1276,13 +1276,13 @@ update_tickles ()
 	# Add tickles for connections that we haven't already got tickles for
 	comm -23 "$_my_connections" "$_my_tickles" |
 	while read _src _dst ; do
-		ctdb addtickle $_src $_dst
+		$CTDB addtickle $_src $_dst
 	done
 
 	# Remove tickles for connections that are no longer there
 	comm -13 "$_my_connections" "$_my_tickles" |
 	while read _src _dst ; do
-		ctdb deltickle $_src $_dst
+		$CTDB deltickle $_src $_dst
 	done
 
 	rm -f "$_my_connections" "$_my_tickles"
-- 
2.5.5


From 2e62555003138948c95ccf1c4759539970812ade 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 03/16] ctdb: use properly configured ctdb in ctdbd_wrapper

This makes ctdbd_wrapper usable in non-standard installs.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/ctdbd_wrapper | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper
index b1f71c3..b6b983c 100755
--- a/ctdb/config/ctdbd_wrapper
+++ b/ctdb/config/ctdbd_wrapper
@@ -256,7 +256,7 @@ start()
 		return 1
 	    fi
 
-	    if ctdb runstate first_recovery startup running >/dev/null 2>&1 ; then
+	    if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
 		return 0
 	    fi
 	fi
@@ -278,7 +278,7 @@ stop()
 	return 0
     fi
 
-    ctdb shutdown
+    $CTDB shutdown
 
     # Wait for remaining CTDB processes to exit...
     _timeout=${CTDB_SHUTDOWN_TIMEOUT:-30}
-- 
2.5.5


From 7ee4744d8480406d0a22577e98cc085ffc4230ad Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:21:56 +0200
Subject: [PATCH 04/16] ctdb: use properly configured ctdb in 00.ctdb

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/00.ctdb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb
index 3bc20d7..bb150ac 100755
--- a/ctdb/config/events.d/00.ctdb
+++ b/ctdb/config/events.d/00.ctdb
@@ -107,7 +107,7 @@ set_ctdb_variables ()
     while read v; do
 	varname="${v#CTDB_SET_}"
 	value=$(eval echo "\$$v")
-	if ctdb setvar $varname $value ; then
+	if $CTDB setvar $varname $value ; then
 	    echo "Set $varname to $value"
 	else
 	    echo "Invalid configuration: CTDB_SET_${varname}=${value}"
@@ -140,7 +140,7 @@ case "$1" in
 	;;
 
     startup)
-	ctdb attach ctdb.tdb persistent
+	$CTDB attach ctdb.tdb persistent
 	;;
 
     *)
-- 
2.5.5


From 4b262b0dc2ad4071fdbe789301a83fe2e28a098a Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:22:24 +0200
Subject: [PATCH 05/16] ctdb: use properly configured ctdb in 01.reclock

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/01.reclock | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/config/events.d/01.reclock b/ctdb/config/events.d/01.reclock
index e2d4d12..da37cf8 100755
--- a/ctdb/config/events.d/01.reclock
+++ b/ctdb/config/events.d/01.reclock
@@ -41,7 +41,7 @@ case "$1" in
 	    echo "Reclock file \"$CTDB_RECOVERY_LOCK\" can not be accessed. Shutting down."
 	    df
 	    sleep 1
-	    ctdb shutdown
+	    $CTDB shutdown
 	fi
 
 	ctdb_check_counter "error" -gt 3
-- 
2.5.5


From 52fc967127dcea1de5136406b03e05a07b7654f0 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:22:44 +0200
Subject: [PATCH 06/16] ctdb: use properly configured ctdb in 10.external

---
 ctdb/config/events.d/10.external | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ctdb/config/events.d/10.external b/ctdb/config/events.d/10.external
index 3fcb0e1..40f4680 100644
--- a/ctdb/config/events.d/10.external
+++ b/ctdb/config/events.d/10.external
@@ -28,12 +28,12 @@ takeover_assigned_ips ()
 {
     ctdb_get_pnn
 
-    ctdb -X ip |
+    $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"
+	    $CTDB moveip "$ip" "$pnn"
 	fi
     done
 }
-- 
2.5.5


From 514b5673b6dcbcc4ed0f4d8396a65e1a0c5b55b0 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:23:07 +0200
Subject: [PATCH 07/16] ctdb: use properly configured ctdb in 13.per_ip_routing

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/13.per_ip_routing | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing
index 56dfc34..cfcd484 100755
--- a/ctdb/config/events.d/13.per_ip_routing
+++ b/ctdb/config/events.d/13.per_ip_routing
@@ -292,7 +292,7 @@ flush_rules_and_routes ()
 # routes.
 add_missing_routes ()
 {
-    ctdb ip -v -X | {
+    $CTDB ip -v -X | {
 	read _x # skip header line
 
 	# Read the rest of the lines.  We're only interested in the
@@ -319,7 +319,7 @@ add_missing_routes ()
 remove_bogus_routes ()
 {
     # Get a IPs current hosted by this node, each anchored with '@'.
-    _ips=$(ctdb ip -v -X | awk -F'|' 'NR > 1 && $4 != "" {printf "@%s@\n", $2}')
+    _ips=$($CTDB ip -v -X | awk -F'|' 'NR > 1 && $4 != "" {printf "@%s@\n", $2}')
 
     ip rule show |
     while read _p _x _i _x _t ; do
@@ -382,7 +382,7 @@ case "$1" in
 	# flush our route cache
 	set_proc sys/net/ipv4/route/flush 1
 
-	ctdb gratiousarp "$ip" "$iface"
+	$CTDB gratiousarp "$ip" "$iface"
 	;;
 
     updateip)
@@ -397,7 +397,7 @@ case "$1" in
 	# flush our route cache
 	set_proc sys/net/ipv4/route/flush 1
 
-	ctdb gratiousarp "$ip" "$niface"
+	$CTDB gratiousarp "$ip" "$niface"
 	tickle_tcp_connections "$ip"
 	;;
 
-- 
2.5.5


From fc28170227cf6684a99bd13c52bfa9dd17fe8286 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:37:00 +0200
Subject: [PATCH 08/16] ctdb: use properly configured ctdb in 10.interfaces

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/10.interface | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ctdb/config/events.d/10.interface b/ctdb/config/events.d/10.interface
index bdb9443..204f4c6 100755
--- a/ctdb/config/events.d/10.interface
+++ b/ctdb/config/events.d/10.interface
@@ -33,7 +33,7 @@ get_all_interfaces ()
 
     # Get the interfaces for which CTDB has public IPs configured.
     # That is, for all but the 1st line, get the 1st field.
-    ctdb_ifaces=$(ctdb -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
+    ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
 
     # Add $ctdb_interfaces and uniquify
     all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
@@ -52,10 +52,10 @@ monitor_interfaces()
 	for _iface in $all_interfaces ; do
 		if interface_monitor "$_iface" ; then
 			up_interfaces_found=true
-			ctdb setifacelink "$_iface" up >/dev/null 2>&1
+			$CTDB setifacelink "$_iface" up >/dev/null 2>&1
 		else
 			down_interfaces_found=true
-			ctdb setifacelink "$_iface" down >/dev/null 2>&1
+			$CTDB setifacelink "$_iface" down >/dev/null 2>&1
 		fi
 	done
 
@@ -233,7 +233,7 @@ case "$1" in
 	flush_route_cache
 
 	# propagate the new mac address
-	ctdb gratiousarp $ip $niface
+	$CTDB gratiousarp $ip $niface
 
 	# tickle all existing connections, so that dropped packets
 	# are retransmited and the tcp streams work
-- 
2.5.5


From 1d550f34e25adae5588433c55593d2a4520e9864 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:44:28 +0200
Subject: [PATCH 09/16] ctdb: use properly configured ctdb in 70.iscsi

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/70.iscsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/config/events.d/70.iscsi b/ctdb/config/events.d/70.iscsi
index 33b71c4..9e75214 100755
--- a/ctdb/config/events.d/70.iscsi
+++ b/ctdb/config/events.d/70.iscsi
@@ -22,7 +22,7 @@ is_ctdb_managed_service || exit 0
 
 case "$1" in
     ipreallocated)
-	all_ips=$(ctdb -X ip | tail -n +2)
+	all_ips=$($CTDB -X ip | tail -n +2)
 
 	# Block the iSCSI port.  Only block for the address families
 	# we have configured.  This copes with, for example, ip6tables
-- 
2.5.5


From fabefab9dae0902560d49fdf5ffd9c1924b86f6a Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:04:48 +0200
Subject: [PATCH 10/16] ctdb: use properly configured ctdb in 91.lvs

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/91.lvs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/config/events.d/91.lvs b/ctdb/config/events.d/91.lvs
index 141f964..434bd2b 100755
--- a/ctdb/config/events.d/91.lvs
+++ b/ctdb/config/events.d/91.lvs
@@ -109,7 +109,7 @@ ipreallocated)
 	ipvsadm -a -t "$CTDB_LVS_PUBLIC_IP" -r 127.0.0.1
 	ipvsadm -a -u "$CTDB_LVS_PUBLIC_IP" -r 127.0.0.1
 
-	ctdb gratiousarp \
+	$CTDB gratiousarp \
 	     "$CTDB_LVS_PUBLIC_IP" "$CTDB_LVS_PUBLIC_IFACE" >/dev/null 2>&1
 
 	flush_route_cache
-- 
2.5.5


From 70d65dd9af478bde6c11c677e170d1f1108b3a75 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 13:05:03 +0200
Subject: [PATCH 11/16] ctdb: use properly configured ctdb in 99.timeout

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/events.d/99.timeout | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/config/events.d/99.timeout b/ctdb/config/events.d/99.timeout
index 2a6495a..c18475f 100755
--- a/ctdb/config/events.d/99.timeout
+++ b/ctdb/config/events.d/99.timeout
@@ -14,7 +14,7 @@ loadconfig ctdb
 
 case "$1" in
     monitor)
-	TIMEOUT=$(ctdb getvar EventScriptTimeout | awk '{print $3}')
+	TIMEOUT=$($CTDB getvar EventScriptTimeout | awk '{print $3}')
 	echo "sleeping for $((TIMEOUT * 2)) seconds..."
 	sleep $((TIMEOUT * 2))
 	;;
-- 
2.5.5


From c2bfd30a6ab43683dad96f2b20758bd575c5c3f7 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:28:56 +0200
Subject: [PATCH 12/16] ctdb: use properly configured ctdb in statd-callout

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/statd-callout | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/ctdb/config/statd-callout b/ctdb/config/statd-callout
index a923d8a..1cbe653 100755
--- a/ctdb/config/statd-callout
+++ b/ctdb/config/statd-callout
@@ -49,7 +49,7 @@ case "$1" in
 	cip="$2"
 	ctdb_get_pnn
 	date=$(date '+%s')
-	ctdb ip -X |
+	$CTDB ip -X |
 	tail -n +2 |
 	while IFS="|" read x sip node x ; do
 	    [ "$node" = "$pnn" ] || continue # not us
@@ -63,7 +63,7 @@ case "$1" in
 	# so we must add it to all the IPs that we serve
 	cip="$2"
 	ctdb_get_pnn
-	ctdb ip -X |
+	$CTDB ip -X |
 	tail -n +2 |
 	while IFS="|" read x sip node x ; do
 	    [ "$node" = "$pnn" ] || continue # not us
@@ -81,12 +81,12 @@ case "$1" in
 	# Filter out lines for any IP addresses that are not currently
 	# hosted public IP addresses.
 	ctdb_get_pnn
-	ctdb_ips=$(ctdb ip | tail -n +2)
+	ctdb_ips=$($CTDB ip | tail -n +2)
 	sed_expr=$(echo "$ctdb_ips" |
 	    awk -v pnn=$pnn 'pnn == $2 { \
                 ip = $1; gsub(/\./, "\\.", ip); \
                 printf "/statd-state@%s@/p\n", ip }')
-        if cat $files | sed -n "$sed_expr" | ctdb ptrans "ctdb.tdb" ; then
+        if cat $files | sed -n "$sed_expr" | $CTDB ptrans "ctdb.tdb" ; then
             rm $files
 	fi
         ;;
@@ -159,13 +159,13 @@ case "$1" in
 	# Construct a sed expression to take catdb output and produce pairs of:
 	#   server-IP client-IP
 	# but only for the server-IPs that are hosted on this node.
-	ctdb_all_ips=$(ctdb ip all | tail -n +2)
+	ctdb_all_ips=$($CTDB ip all | tail -n +2)
 	sed_expr=$(echo "$ctdb_all_ips" |
 	    awk -v pnn=$pnn 'pnn == $2 { \
                 ip = $1; gsub(/\./, "\\.", ip); \
                 printf "s/^key.*=.*statd-state@\\(%s\\)@\\([^\"]*\\).*/\\1 \\2/p\n", ip }')
 
-	statd_state=$(ctdb catdb ctdb.tdb | sed -n "$sed_expr" | sort)
+	statd_state=$($CTDB catdb ctdb.tdb | sed -n "$sed_expr" | sort)
 	[ -n "$statd_state" ] || exit 0
 
 	smnotify="${CTDB_HELPER_BINDIR}/smnotify"
@@ -195,7 +195,7 @@ case "$1" in
 		"$smnotify" --client=$cip --ip=$sip --server=$NFS_HOSTNAME --stateval=$stateval
 	    done
 
-	    echo "$items" | ctdb ptrans "ctdb.tdb"
+	    echo "$items" | $CTDB ptrans "ctdb.tdb"
 	}
 
 	# Remove any stale touch files (i.e. for IPs not currently
-- 
2.5.5


From f24ac00e6ea1713960a11e0c07bfdad6b36de7cd Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 12:32:04 +0200
Subject: [PATCH 13/16] ctdb: use properly configured ctdb in
 debug-hung-script.sh

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/debug-hung-script.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/config/debug-hung-script.sh b/ctdb/config/debug-hung-script.sh
index 9bde684..cef004b 100755
--- a/ctdb/config/debug-hung-script.sh
+++ b/ctdb/config/debug-hung-script.sh
@@ -47,7 +47,7 @@ fi
 
     if [ "$2" != "init" ] ; then
 	echo "---- ctdb scriptstatus ${2}: ----"
-	ctdb scriptstatus "$2"
+	$CTDB scriptstatus "$2"
     fi
 
     echo "===== End of hung script debug for PID=\"$1\", event=\"$2\" ====="
-- 
2.5.5


From 28ae001dc16f252c351360e7d9f022a48793c5d7 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Thu, 9 Jun 2016 13:55:29 +0200
Subject: [PATCH 14/16] ctdb: make sure scripts using $CTDB called by test find
 ctdb

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/tests/eventscripts/scripts/local.sh     | 3 +++
 ctdb/tests/simple/scripts/local_daemons.bash | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh
index 51f3858..eed41c5 100644
--- a/ctdb/tests/eventscripts/scripts/local.sh
+++ b/ctdb/tests/eventscripts/scripts/local.sh
@@ -20,6 +20,9 @@ export EVENTSCRIPTS_PATH
 
 PATH="${EVENTSCRIPTS_PATH}:${PATH}"
 
+CTDB="ctdb"
+export CTDB
+
 export EVENTSCRIPTS_TESTS_VAR_DIR="${TEST_VAR_DIR}/unit_eventscripts"
 if [ -d "$EVENTSCRIPTS_TESTS_VAR_DIR" -a \
     "$EVENTSCRIPTS_TESTS_VAR_DIR" != "/unit_eventscripts" ] ; then
diff --git a/ctdb/tests/simple/scripts/local_daemons.bash b/ctdb/tests/simple/scripts/local_daemons.bash
index fc0e47d..fc20fbd 100644
--- a/ctdb/tests/simple/scripts/local_daemons.bash
+++ b/ctdb/tests/simple/scripts/local_daemons.bash
@@ -20,6 +20,8 @@ fi
 
 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
 
+export CTDB=ctdb
+
 #######################################
 
 daemons_stop ()
-- 
2.5.5


From d1ea023c36753bc5070468c84aa174852c2e1019 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 8 Jun 2016 11:46:00 +0200
Subject: [PATCH 15/16] ctdb: move mabye_set from ctdbd_wrapper to functions
 for re-use

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/ctdbd_wrapper | 22 ----------------------
 ctdb/config/functions     | 31 +++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper
index b6b983c..a58d5ca 100755
--- a/ctdb/config/ctdbd_wrapper
+++ b/ctdb/config/ctdbd_wrapper
@@ -116,28 +116,6 @@ 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}"
-    }
-
     if [ -z "$CTDB_RECOVERY_LOCK" ] ; then
         echo "No recovery lock specified. Starting CTDB without split brain prevention."
     fi
diff --git a/ctdb/config/functions b/ctdb/config/functions
index e32826d..122a0f2 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -26,6 +26,37 @@ if [ -z "$CTDB_HELPER_BINDIR" ] ; then
     CTDB_HELPER_BINDIR="/usr/local/libexec/ctdb"
 fi
 
+
+#########################################
+# Convert environment variables into
+# commandline options or ctdbd and ctdb.
+#
+# The options are stored in the variable
+# ctdb_options that the caller should have
+# initialized.
+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}"
+}
+
+
 #######################################
 # pull in a system config file, if any
 
-- 
2.5.5


From 6e8da3b1630e7b6afff4d2e90cdc41b35129243a 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 16/16] ctdb: add ctdb_wrapper as a wrapper to call ctdb from
 the cmdline

This is useful for non-standard installations since
it reads the socket from the config file so the user
does not need to specify it. Just a convenience tool
which removes the need to set environment variables
prior to calling ctdb.

This is similar to ctdbd_wrapper for ctdbd but
much more simple.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/config/ctdb_wrapper | 33 +++++++++++++++++++++++++++++++++
 ctdb/wscript             | 12 ++++++++++--
 2 files changed, 43 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..e4718a0
--- /dev/null
+++ b/ctdb/config/ctdb_wrapper
@@ -0,0 +1,33 @@
+#!/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"
+
+build_ctdb_options ()
+{
+	ctdb_options=""
+
+	maybe_set "--socket" "$CTDB_SOCKET"
+}
+
+############################################################
+
+build_ctdb_options
+
+if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
+	if [ "$CTDB_VALGRIND" = "yes" ] ; then
+		CTDB_VALIGRIND="valgrind -q --log-file=/usr/local/var/log/ctdb_valgrind"
+	fi
+	ctdb_tool="${CTDB_VALGRIND} ${ctdb_tool}"
+	ctdb_options="${ctdb_options} --valgrinding"
+fi
+
+eval "$CTDB" "$ctdb_options" "$@"
diff --git a/ctdb/wscript b/ctdb/wscript
index 6a411da..9380378 100755
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -515,9 +515,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)
@@ -573,6 +574,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

-------------- 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/20160609/1c5add0c/signature.sig>


More information about the samba-technical mailing list