Dont store temporary runtime data in $CTDB_BASE/state
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 3 Sep 2010 02:35:25 +0000 (12:35 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 3 Sep 2010 02:43:28 +0000 (12:43 +1000)
since that will usually be /etc/ctdb/state and storing this under /etc is just
wrong.

Add a new variable CTDB_VARDIR that defaults to /var/ctdb and store the data there instead.

config/ctdb.init
config/events.d/00.ctdb
config/events.d/13.per_ip_routing
config/events.d/20.multipathd
config/events.d/50.samba
config/events.d/60.nfs
config/events.d/62.cnfs
config/events.d/README
config/functions
config/statd-callout

index fc66ab2..25e158f 100755 (executable)
@@ -39,6 +39,10 @@ unset TMPDIR
     export CTDB_BASE="/etc/ctdb"
 }
 
+[ -z "$CTDB_VARDIR" ] && {
+    export CTDB_VARDIR="/var/ctdb"
+}
+
 . $CTDB_BASE/functions
 loadconfig network
 loadconfig ctdb
index 7e9e386..8ff6488 100755 (executable)
@@ -15,10 +15,10 @@ loadconfig
 case "$1" in 
      init)
         # make sure we have a blank state directory for the scripts to work with
-       /bin/rm -rf $CTDB_BASE/state
-       /bin/mkdir -p $CTDB_BASE/state || {
+       /bin/rm -rf $CTDB_VARDIR/state
+       /bin/mkdir -p $CTDB_VARDIR/state || {
            ret=$?
-           echo "/bin/mkdir -p $CTDB_BASE/state - failed - $ret"
+           echo "/bin/mkdir -p $CTDB_VARDIR/state - failed - $ret"
            exit $ret
        }
        ;;
@@ -37,15 +37,15 @@ case "$1" in
     startup)
        # Pull optional ctdb configuration data out of config.tdb
        PUBLICADDRESSESKEY='public-addresses:node#'`ctdb -t 1 xpnn|sed -e "s/.*://"`
-       rm -f $CTDB_BASE/state/public_addresses
-       ctdb pfetch config.tdb $PUBLICADDRESSESKEY $CTDB_BASE/state/public_addresses
+       rm -f $CTDB_VARDIR/state/public_addresses
+       ctdb pfetch config.tdb $PUBLICADDRESSESKEY $CTDB_VARDIR/state/public_addresses
        [ "$?" = "0" ] && [ `stat --format="%s" /etc/ctdb/state/public_addresses` != "0" ] && [ ! -z "$CTDB_PUBLIC_ADDRESSES" ] && {
-               diff $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES >/dev/null 2>/dev/null
+               diff $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES >/dev/null 2>/dev/null
                [ $? = "0" ] || {
                        echo CTDB public address configuration had been updated.
                        echo Extracting new configuration from database.
-                       diff $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES
-                       cp $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES
+                       diff $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES
+                       cp $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES
                        echo Restarting CTDB
                        service ctdb restart &
                }
index 6b51b05..c734bbc 100755 (executable)
@@ -4,7 +4,7 @@
 loadconfig
 
 [ -z "$CTDB_PER_IP_ROUTING_STATE" ] && {
-       CTDB_PER_IP_ROUTING_STATE="$CTDB_BASE/state/per_ip_routing"
+       CTDB_PER_IP_ROUTING_STATE="$CTDB_VARDIR/state/per_ip_routing"
 }
 
 AUTO_LINK_LOCAL="no"
index 091a773..2f484a4 100644 (file)
@@ -16,7 +16,7 @@ loadconfig
        exit 0
 }
 
-MPFAILURE=$CTDB_BASE/state/multipathd/failure
+MPFAILURE=$CTDB_VARDIR/state/multipathd/failure
 
 multipathd_check_background()
 {
@@ -78,7 +78,7 @@ case "$1" in
     startup)
        # create a state directory to keep/track the multipath device
        # state
-       /bin/mkdir -p $CTDB_BASE/state/multipathd
+       /bin/mkdir -p $CTDB_VARDIR/state/multipathd
        exit 0
        ;;
 
index 23dd060..047f9e0 100755 (executable)
@@ -34,7 +34,7 @@ loadconfig
 
 start_samba() {
        # create the state directory for samba
-       /bin/mkdir -p $CTDB_BASE/state/samba
+       /bin/mkdir -p $CTDB_VARDIR/state/samba
 
        # make sure samba is not already started
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
@@ -101,13 +101,13 @@ stop_samba() {
 }
 
 # we keep a cached copy of smb.conf here
-smbconf_cache="$CTDB_BASE/state/samba/smb.conf.cache"
+smbconf_cache="$CTDB_VARDIR/state/samba/smb.conf.cache"
 
 
 #############################################
 # update the smb.conf cache in the foreground
 testparm_foreground_update() {
-    mkdir -p "$CTDB_BASE/state/samba" || exit 1
+    mkdir -p "$CTDB_VARDIR/state/samba" || exit 1
     testparm -s 2> /dev/null | egrep -v 'registry.shares.=|include.=' > "$smbconf_cache"
 }
 
@@ -215,13 +215,13 @@ case "$1" in
      monitor)
        # Create a dummy file to track when we need to do periodic cleanup
        # of samba databases
-       [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
-               touch $CTDB_BASE/state/samba/periodic_cleanup
+       [ -f $CTDB_VARDIR/state/samba/periodic_cleanup ] || {
+               touch $CTDB_VARDIR/state/samba/periodic_cleanup
        }
-       [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
+       [ `/usr/bin/find $CTDB_VARDIR/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
                # Cleanup the databases
                periodic_cleanup
-               touch $CTDB_BASE/state/samba/periodic_cleanup
+               touch $CTDB_VARDIR/state/samba/periodic_cleanup
        }
 
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
index 35f96c2..60de41e 100755 (executable)
@@ -2,8 +2,8 @@
 # script to manage nfs in a clustered environment
 
 start_nfs() {
-       /bin/mkdir -p $CTDB_BASE/state/nfs
-       /bin/mkdir -p $CTDB_BASE/state/statd/ip
+       /bin/mkdir -p $CTDB_VARDIR/state/nfs
+       /bin/mkdir -p $CTDB_VARDIR/state/statd/ip
        startstop_nfs stop
        startstop_nfs start
        echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
@@ -25,7 +25,7 @@ case "$1" in
        ;;
      startup)
        ctdb_service_start
-       touch $CTDB_BASE/state/statd/update-trigger
+       touch $CTDB_VARDIR/state/statd/update-trigger
        ;;
 
      shutdown)
@@ -103,11 +103,11 @@ case "$1" in
 
        # once every 60 seconds, update the statd state database for which
        # clients need notifications
-       LAST_UPDATE=`stat --printf="%Y" $CTDB_BASE/state/statd/update-trigger`
+       LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger`
        CURRENT_TIME=`date +"%s"`
        expr "$CURRENT_TIME" ">" "(" "$LAST_UPDATE" "+" "60" ")" >/dev/null 2>/dev/null
        [ $? = "0" ] && {
-           touch $CTDB_BASE/state/statd/update-trigger
+           touch $CTDB_VARDIR/state/statd/update-trigger
            $CTDB_BASE/statd-callout updatelocal &
            $CTDB_BASE/statd-callout updateremote &
        }
index 2577675..e0af722 100755 (executable)
@@ -5,7 +5,7 @@
 
 loadconfig
 
-STATEDIR=$CTDB_BASE/state/gpfs
+STATEDIR=$CTDB_VARDIR/state/gpfs
 
 
 # filesystems needed by nfs
index ef345b5..c05a1fd 100644 (file)
@@ -29,7 +29,7 @@ init
        and prepare the basic setup.
        At this stage 'ctdb' commands won't work.
 
-       Example: 00.ctdb cleans up $CTDB_BASE/state
+       Example: 00.ctdb cleans up $CTDB_VARDIR/state
 
 setup
        This event does not take any additional arguments.
@@ -37,7 +37,7 @@ setup
        This event is used to do some cleanup work from earlier runs
        and prepare the basic setup.
 
-       Example: 00.ctdb cleans up $CTDB_BASE/state
+       Example: 00.ctdb cleans up $CTDB_VARDIR/state
 
 startup
        This event does not take any additional arguments.
index a20cadf..9771905 100755 (executable)
@@ -231,7 +231,7 @@ kill_tcp_connections() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -281,7 +281,7 @@ kill_tcp_connections_local_only() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -323,7 +323,7 @@ tickle_tcp_connections() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -453,7 +453,7 @@ add_ip_to_iface()
        local _iface=$1
        local _ip=$2
        local _maskbits=$3
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -476,7 +476,7 @@ delete_ip_from_iface()
        local _iface=$1
        local _ip=$2
        local _maskbits=$3
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -500,7 +500,7 @@ setup_iface_ip_readd_script()
        local _ip=$2
        local _maskbits=$3
        local _readd_script=$4
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -779,7 +779,7 @@ iptables()
 ########################################################
 
 # Temporary directory for tickles.
-tickledir="$CTDB_BASE/state/tickles"
+tickledir="$CTDB_VARDIR/state/tickles"
 mkdir -p "$tickledir"
 
 update_tickles ()
index 9808cb9..39be9d3 100755 (executable)
@@ -9,6 +9,10 @@
     export CTDB_BASE="/etc/ctdb"
 }
 
+[ -z "$CTDB_VARDIR" ] && {
+    export CTDB_VARDIR="/var/ctdb"
+}
+
 . $CTDB_BASE/functions
 loadconfig ctdb
 loadconfig nfs
@@ -30,8 +34,8 @@ case "$1" in
                        continue
                } 
                IP=`echo $LINE | cut -f2 -d:`
-               /bin/mkdir -p $CTDB_BASE/state/statd/ip/$IP
-               touch $CTDB_BASE/state/statd/ip/$IP/$2
+               /bin/mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
+               touch $CTDB_VARDIR/state/statd/ip/$IP/$2
        done
        ;;
   del-client)
@@ -45,8 +49,8 @@ case "$1" in
                        continue
                } 
                IP=`echo $LINE | cut -f2 -d:`
-               mkdir -p $CTDB_BASE/state/statd/ip/$IP
-               /bin/rm -f $CTDB_BASE/state/statd/ip/$IP/$2
+               mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
+               /bin/rm -f $CTDB_VARDIR/state/statd/ip/$IP/$2
        done
        ;;
   updatelocal)
@@ -59,25 +63,25 @@ case "$1" in
                } 
                IP=`echo $LINE | cut -f2 -d:`
 
-               mkdir -p $CTDB_BASE/state/statd/ip/$IP
+               mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
 
-               rm -f $CTDB_BASE/state/statd/ip/$IP.tar
-               tar cfP $CTDB_BASE/state/statd/ip/$IP.tar $CTDB_BASE/state/statd/ip/$IP
+               rm -f $CTDB_VARDIR/state/statd/ip/$IP.tar
+               tar cfP $CTDB_VARDIR/state/statd/ip/$IP.tar $CTDB_VARDIR/state/statd/ip/$IP
 
-               rm -f $CTDB_BASE/state/statd/ip/$IP.rec
-               ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_BASE/state/statd/ip/$IP.rec 2>/dev/null
+               rm -f $CTDB_VARDIR/state/statd/ip/$IP.rec
+               ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.rec 2>/dev/null
                [ "$?" = "0" ] || {
                        # something went wrong,  try storing this data
                        echo No record. Store STATD state data for $IP
-                       ctdb pstore ctdb.tdb statd-state:$IP $CTDB_BASE/state/statd/ip/$IP.tar 2>/dev/null
+                       ctdb pstore ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.tar 2>/dev/null
                        continue
                }
 
-               cmp $CTDB_BASE/state/statd/ip/$IP.tar $CTDB_BASE/state/statd/ip/$IP.rec >/dev/null 2>/dev/null
+               cmp $CTDB_VARDIR/state/statd/ip/$IP.tar $CTDB_VARDIR/state/statd/ip/$IP.rec >/dev/null 2>/dev/null
                [ "$?" = "0" ] || {
                        # something went wrong,  try storing this data
                        echo Updated record. Store STATD state data for $IP
-                       ctdb pstore ctdb.tdb statd-state:$IP $CTDB_BASE/state/statd/ip/$IP.tar 2>/dev/null
+                       ctdb pstore ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.tar 2>/dev/null
                        continue
                }
        done
@@ -93,16 +97,16 @@ case "$1" in
                } 
                IP=`echo $LINE | cut -f2 -d:`
 
-               mkdir -p $CTDB_BASE/state/statd/ip/$IP
+               mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
 
-               rm -f $CTDB_BASE/state/statd/ip/$IP.rec
-               ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_BASE/state/statd/ip/$IP.rec 2>/dev/null
+               rm -f $CTDB_VARDIR/state/statd/ip/$IP.rec
+               ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.rec 2>/dev/null
                [ "$?" = "0" ] || {
                        continue
                }
 
-               rm -f $CTDB_BASE/state/statd/ip/$IP/*
-               tar xfP $CTDB_BASE/state/statd/ip/$IP.rec
+               rm -f $CTDB_VARDIR/state/statd/ip/$IP/*
+               tar xfP $CTDB_VARDIR/state/statd/ip/$IP.rec
        done
        ;;
 
@@ -181,8 +185,8 @@ case "$1" in
                } 
                IP=`echo $LINE | cut -f2 -d:`
 
-               ls $CTDB_BASE/state/statd/ip/$IP | while read CLIENT; do
-                       rm $CTDB_BASE/state/statd/ip/$IP/$CLIENT
+               ls $CTDB_VARDIR/state/statd/ip/$IP | while read CLIENT; do
+                       rm $CTDB_VARDIR/state/statd/ip/$IP/$CLIENT
                        /usr/bin/smnotify --client=$CLIENT --ip=$IP --server=$ip --stateval=$STATE
                        /usr/bin/smnotify --client=$CLIENT --ip=$IP --server=$NFS_HOSTNAME --stateval=$STATE
                        STATE=`expr "$STATE" "+" "1"`