From c62490569b81408a7577234434663a072059c798 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Sep 2007 14:14:03 +1000 Subject: [PATCH] cope with non-standard install dirs in event scripts (This used to be ctdb commit 52fff5345873690a9cc86495f414343eaa3bd540) --- ctdb/config/ctdb.init | 8 ++++++-- ctdb/config/events.d/00.ctdb | 6 +++--- ctdb/config/events.d/10.interface | 6 +++--- ctdb/config/events.d/40.vsftpd | 12 ++++++------ ctdb/config/events.d/50.samba | 12 ++++++------ ctdb/config/events.d/60.nfs | 22 +++++++++++----------- ctdb/config/events.d/61.nfstickle | 4 ++-- ctdb/config/functions | 4 ++-- ctdb/config/statd-callout | 14 +++++++++----- ctdb/server/ctdbd.c | 4 ++++ 10 files changed, 52 insertions(+), 40 deletions(-) diff --git a/ctdb/config/ctdb.init b/ctdb/config/ctdb.init index 91b1094ebe1..dbc1bef1c23 100755 --- a/ctdb/config/ctdb.init +++ b/ctdb/config/ctdb.init @@ -34,7 +34,11 @@ fi # Avoid using root's TMPDIR unset TMPDIR -. /etc/ctdb/functions +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +. $CTDB_BASE/functions loadconfig network loadconfig ctdb @@ -100,7 +104,7 @@ stop() { [ $count -gt 10 ] && { echo -n $"killing ctdbd " killall -q -9 ctdbd - pkill -9 -f /etc/ctdb/events.d/ + pkill -9 -f $CTDB_BASE/events.d/ } done case $init_style in diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb index c12d58c5424..abcb651307f 100755 --- a/ctdb/config/events.d/00.ctdb +++ b/ctdb/config/events.d/00.ctdb @@ -9,7 +9,7 @@ # releaseip : called when an IP address is released # recovered : called when ctdb has finished a recovery event -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig ctdb # ensure we have /bin and /usr/bin in the path @@ -21,8 +21,8 @@ shift case $cmd in startup) # make sure we have a blank state directory for the scripts to work with - /bin/rm -rf /etc/ctdb/state - /bin/mkdir -p /etc/ctdb/state + /bin/rm -rf $CTDB_BASE/state + /bin/mkdir -p $CTDB_BASE/state # set any tunables from the config file set | grep ^CTDB_SET_ | cut -d_ -f3- | diff --git a/ctdb/config/events.d/10.interface b/ctdb/config/events.d/10.interface index 6e43fa03438..7d95a198373 100755 --- a/ctdb/config/events.d/10.interface +++ b/ctdb/config/events.d/10.interface @@ -5,14 +5,14 @@ # this adds/removes IPs from your # public interface -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig ctdb cmd="$1" shift [ -z "$CTDB_PUBLIC_ADDRESSES" ] && { - CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses + CTDB_PUBLIC_ADDRESSES=$CTDB_BASE/public_addresses } [ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && { @@ -27,7 +27,7 @@ kill_tcp_connections() { _failed=0 _killcount=0 - connfile="/etc/ctdb/state/connections.$_IP" + connfile="$CTDB_BASE/state/connections.$_IP" netstat -tn |egrep "^tcp.*\s+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile while read dest src; do srcip=`echo $src | cut -d: -f1` diff --git a/ctdb/config/events.d/40.vsftpd b/ctdb/config/events.d/40.vsftpd index 6f48e37b32a..525b69bf79d 100755 --- a/ctdb/config/events.d/40.vsftpd +++ b/ctdb/config/events.d/40.vsftpd @@ -1,7 +1,7 @@ #!/bin/sh # event strict to manage vsftpd in a cluster environment -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig vsftpd [ "$CTDB_MANAGES_VSFTPD" = "yes" ] || exit 0 @@ -11,7 +11,7 @@ shift case $cmd in startup) - /bin/mkdir -p /etc/ctdb/state/vsftpd + /bin/mkdir -p $CTDB_BASE/state/vsftpd # make sure the service is stopped first service vsftpd stop > /dev/null 2>&1 @@ -23,22 +23,22 @@ case $cmd in ;; takeip) - echo "restart" >> /etc/ctdb/state/vsftpd/restart + echo "restart" >> $CTDB_BASE/state/vsftpd/restart ;; releaseip) - echo "restart" >> /etc/ctdb/state/vsftpd/restart + echo "restart" >> $CTDB_BASE/state/vsftpd/restart ;; recovered) # if we have taken or released any ips we must # restart vsftpd to ensure that all tcp connections are reset - [ -f /etc/ctdb/state/vsftpd/restart ] && { + [ -f $CTDB_BASE/state/vsftpd/restart ] && { service vsftpd stop > /dev/null 2>&1 service vsftpd start } >/dev/null 2>&1 - /bin/rm -f /etc/ctdb/state/vsftpd/restart + /bin/rm -f $CTDB_BASE/state/vsftpd/restart ;; esac diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba index 04aeaa3c745..54c2645b9af 100755 --- a/ctdb/config/events.d/50.samba +++ b/ctdb/config/events.d/50.samba @@ -3,7 +3,7 @@ PATH=/bin:/usr/bin:$PATH -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig ctdb cmd="$1" @@ -28,7 +28,7 @@ periodic_cleanup() { case $cmd in startup) # create the state directory for samba - /bin/mkdir -p /etc/ctdb/state/samba + /bin/mkdir -p $CTDB_BASE/state/samba # wait for all shared directories to become available smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2` @@ -79,13 +79,13 @@ case $cmd in monitor) # Create a dummy file to track when we need to do periodic cleanup # of samba databases - [ -f /etc/ctdb/state/samba/periodic_cleanup ] || { - touch /etc/ctdb/state/samba/periodic_cleanup + [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || { + touch $CTDB_BASE/state/samba/periodic_cleanup } - [ `/usr/bin/find /etc/ctdb/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && { + [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && { # Cleanup the databases periodic_cleanup - touch /etc/ctdb/state/samba/periodic_cleanup + touch $CTDB_BASE/state/samba/periodic_cleanup } testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && { diff --git a/ctdb/config/events.d/60.nfs b/ctdb/config/events.d/60.nfs index f19dfea1494..7d1a3801662 100755 --- a/ctdb/config/events.d/60.nfs +++ b/ctdb/config/events.d/60.nfs @@ -1,7 +1,7 @@ #!/bin/sh # script to manage nfs in a clustered environment -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig nfs [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0 @@ -14,8 +14,8 @@ PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH case $cmd in startup) - /bin/mkdir -p /etc/ctdb/state/nfs - /bin/mkdir -p /etc/ctdb/state/statd/ip + /bin/mkdir -p $CTDB_BASE/state/nfs + /bin/mkdir -p $CTDB_BASE/state/statd/ip /bin/mkdir -p $STATD_SHARED_DIRECTORY ctdb_wait_directories "nfslock" "$STATD_SHARED_DIRECTORY" @@ -41,11 +41,11 @@ case $cmd in takeip) ip=$2 - echo $ip >> /etc/ctdb/state/statd/restart + echo $ip >> $CTDB_BASE/state/statd/restart # having a list of what IPs we have allows statd to do the right - # thing via /etc/ctdb/statd-callout - /bin/touch /etc/ctdb/state/statd/ip/$ip + # thing via $CTDB_BASE/statd-callout + /bin/touch $CTDB_BASE/state/statd/ip/$ip exit 0 ;; @@ -54,19 +54,19 @@ case $cmd in ip=$2 maskbits=$3 - echo $ip >> /etc/ctdb/state/statd/restart - /bin/rm -f /etc/ctdb/state/statd/ip/$ip + echo $ip >> $CTDB_BASE/state/statd/restart + /bin/rm -f $CTDB_BASE/state/statd/ip/$ip exit 0 ;; recovered) # always restart the lockmanager so that we start with a clusterwide # graceperiod when ip addresses has changed - [ -x /etc/ctdb/statd-callout ] && { - /etc/ctdb/statd-callout notify & + [ -x $CTDB_BASE/statd-callout ] && { + $CTDB_BASE/statd-callout notify & } >/dev/null 2>&1 - /bin/rm -f /etc/ctdb/state/statd/restart + /bin/rm -f $CTDB_BASE/state/statd/restart ;; monitor) diff --git a/ctdb/config/events.d/61.nfstickle b/ctdb/config/events.d/61.nfstickle index d8901437492..d71dfbeed5e 100755 --- a/ctdb/config/events.d/61.nfstickle +++ b/ctdb/config/events.d/61.nfstickle @@ -3,7 +3,7 @@ PATH=/bin:/usr/bin:$PATH -. /etc/ctdb/functions +. $CTDB_BASE/functions loadconfig nfs cmd="$1" @@ -14,7 +14,7 @@ shift case $cmd in startup) - mkdir -p /etc/ctdb/state/nfstickle + mkdir -p $CTDB_BASE/state/nfstickle mkdir -p $NFS_TICKLE_SHARED_DIRECTORY/`hostname` # we rely on fast tcp wait1 recycling echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle diff --git a/ctdb/config/functions b/ctdb/config/functions index f7ffd01079f..3c39addc02a 100644 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -8,8 +8,8 @@ loadconfig() { . /etc/sysconfig/$name elif [ -f /etc/default/$name ]; then . /etc/default/$name - elif [ -f /etc/ctdb/sysconfig/$name ]; then - . /etc/ctdb/sysconfig/$name + elif [ -f $CTDB_BASE/sysconfig/$name ]; then + . $CTDB_BASE/sysconfig/$name fi } diff --git a/ctdb/config/statd-callout b/ctdb/config/statd-callout index f7389fc3b5c..f582a1a8e02 100755 --- a/ctdb/config/statd-callout +++ b/ctdb/config/statd-callout @@ -5,7 +5,11 @@ # /etc/sysconfig/nfs: # STATD_HOSTNAME="myhostname -H /etc/ctdb/statd-callout" -. /etc/ctdb/functions +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +. $CTDB_BASE/functions loadconfig nfs [ -z "$STATD_SHARED_DIRECTORY" ] && { @@ -24,7 +28,7 @@ case "$1" in add-client) # the callout does not tell us to which ip the client connected # so we must add it to all the ips that we serve - for f in `/bin/ls /etc/ctdb/state/statd/ip/*`; do + for f in `/bin/ls $CTDB_BASE/state/statd/ip/*`; do ip=`/bin/basename $f` [ -d $STATD_SHARED_DIRECTORY/$ip ] || /bin/mkdir $STATD_SHARED_DIRECTORY/$ip /bin/touch $STATD_SHARED_DIRECTORY/$ip/$2 @@ -33,7 +37,7 @@ case "$1" in del-client) # the callout does not tell us to which ip the client connected # so we must add it to all the ips that we serve - for f in `/bin/ls /etc/ctdb/state/statd/ip/*`; do + for f in `/bin/ls $CTDB_BASE/state/statd/ip/*`; do ip=`/bin/basename $f` /bin/rm -f $STATD_SHARED_DIRECTORY/$ip/$2 done @@ -81,7 +85,7 @@ case "$1" in sleep 2 # copy all monitored clients on this node to the local lockmanager - for f in `/bin/ls /etc/ctdb/state/statd/ip/* 2>/dev/null`; do + for f in `/bin/ls $CTDB_BASE/state/statd/ip/* 2>/dev/null`; do ip=`/bin/basename $f` [ -d $STATD_SHARED_DIRECTORY/$ip ] && [ -x /usr/bin/smnotify ] && { for g in `/bin/ls $STATD_SHARED_DIRECTORY/$ip/* 2>/dev/null`; do @@ -122,7 +126,7 @@ case "$1" in # Both 2a and 2b are commonly used in lockmanagers since they maximize # probability that the client will accept the statd notify packet and # not just ignore it. - for f in `/bin/ls /etc/ctdb/state/statd/ip/* 2>/dev/null`; do + for f in `/bin/ls $CTDB_BASE/state/statd/ip/* 2>/dev/null`; do ip=`/bin/basename $f` [ -d $STATD_SHARED_DIRECTORY/$ip ] && [ -x /usr/bin/smnotify ] && { for g in `/bin/ls $STATD_SHARED_DIRECTORY/$ip/* 2>/dev/null`; do diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index 500773375eb..92f4b86c537 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -229,6 +229,10 @@ int main(int argc, const char *argv[]) ctdb->do_setsched = !options.no_setsched; + /* setup a environment variable for the event scripts to use to find the + installation directory */ + setenv("CTDB_BASE", ETCDIR "/ctdb", 1); + /* start the protocol running (as a child) */ return ctdb_start_daemon(ctdb, interactive?False:True); }