Eventscript argument cleanups and introduction of ctdb_standard_event_handler.
authorMartin Schwenke <martin@meltin.net>
Tue, 1 Dec 2009 06:43:47 +0000 (17:43 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 1 Dec 2009 06:43:47 +0000 (17:43 +1100)
The functions file no longer causes a side-effect by doing a shift.
It also doesn't set a convenience variable for $1.

All eventscripts now explicitly use "$1" in their case statement, as
does the initscript.  The absence of a shift means that the
takeip/releaseip events now explicitly reference $2-$4 rather than
$1-$3.

New function ctdb_standard_event_handler handles the status and
setstatus events, and exits for either of those events.  It is called
via a default case in each eventscript, replacing an explicit status
case where applicable.

Signed-off-by: Martin Schwenke <martin@meltin.net>
17 files changed:
config/ctdb.init
config/events.d/00.ctdb
config/events.d/01.reclock
config/events.d/10.interface
config/events.d/11.natgw [changed mode: 0644->0755]
config/events.d/11.routing
config/events.d/20.multipathd [changed mode: 0644->0755]
config/events.d/31.clamd [changed mode: 0644->0755]
config/events.d/40.vsftpd
config/events.d/41.httpd
config/events.d/50.samba
config/events.d/60.nfs
config/events.d/61.nfstickle
config/events.d/70.iscsi
config/events.d/91.lvs
config/events.d/99.timeout
config/functions

index 4bd570d343acf400db73dc65ae47d88fa8cb0896..67747fd149da73f95a2d84d146b5fa4d1249cbdf 100755 (executable)
@@ -250,7 +250,7 @@ status() {
 }
 
 
-case "$cmd" in
+case "$1" in
     start)
        start
        ;;
index f2ec5e85b8379f0453bade7c7f09f0d9fc8164b5..bad129f538e69462238562519c5aa75fe75f1e34 100755 (executable)
@@ -12,7 +12,7 @@
 . $CTDB_BASE/functions
 loadconfig
 
-case $cmd in 
+case "$1" in 
      startup)
         # make sure we have a blank state directory for the scripts to work with
        /bin/rm -rf $CTDB_BASE/state
@@ -39,6 +39,10 @@ case $cmd in
                        ctdb shutdown
                }
        }
+
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
 # all OK
index 1b6cbf09e440a2aa5eaada9f869bd2ddaaf70335..919d29697fba52cbcf5e28f06c3a6500119a52d4 100755 (executable)
@@ -4,7 +4,7 @@
 . $CTDB_BASE/functions
 loadconfig
 
-case $cmd in 
+case "$1" in 
     startup)
        ctdb_counter_init
        ;;
@@ -37,8 +37,9 @@ case $cmd in
 
        ctdb_check_counter_limit 3 quiet
        ;;
-    status)
-       ctdb_checkstatus || exit $?
+
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
index da6d903d53bf65be161a725bf926bfd1f714071f..e24cc36a164151ed9bd9e3c1f8afde8fffb3ed09 100755 (executable)
@@ -17,7 +17,7 @@ loadconfig
        exit 0
 }
 
-case $cmd in 
+case "$1" in 
      #############################
      # called when ctdbd starts up
      startup)
@@ -41,13 +41,13 @@ case $cmd in
      ################################################
      # called when ctdbd wants to claim an IP address
      takeip)
-       if [ $# != 3 ]; then
+       if [ $# != 4 ]; then
           echo "must supply interface, IP and maskbits"
           exit 1
        fi
-       iface=$1
-       ip=$2
-       maskbits=$3
+       iface=$2
+       ip=$3
+       maskbits=$4
 
        # we make sure the interface is up first
        /sbin/ip link set $iface up || {
@@ -68,7 +68,7 @@ case $cmd in
      ##################################################
      # called when ctdbd wants to release an IP address
      releaseip)
-       if [ $# != 3 ]; then
+       if [ $# != 4 ]; then
           echo "must supply interface, IP and maskbits"
           exit 1
        fi
@@ -83,9 +83,9 @@ case $cmd in
        # 2) use netstat -tn to find existing connections, and kill them 
        # 3) remove the IP from the interface
        # 4) remove the firewall rule
-       iface=$1
-       ip=$2
-       maskbits=$3
+       iface=$2
+       ip=$3
+       maskbits=$4
 
        failed=0
        # we do an extra delete to cope with the script being killed
@@ -174,8 +174,8 @@ case $cmd in
            esac
        done
        ;;
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
old mode 100644 (file)
new mode 100755 (executable)
index 3a35094..ee7b4f9
@@ -22,7 +22,7 @@ delete_all() {
 
 }
 
-case $cmd in 
+case "$1" in 
     startup)
        # do not respond to ARPs that are for ip addresses with scope 'host'
        echo 3 > /proc/sys/net/ipv4/conf/all/arp_ignore
@@ -70,6 +70,9 @@ case $cmd in
        delete_all
        ;;
 
+    *)
+       ctdb_standard_event_handler "@"
+       ;;
 esac
 
 exit 0
index cb34e417a8f197fcf1a10893bbbd62b12d8e1169..c265c382d0c60008ab7043ed57dd3ce728a5ea74 100755 (executable)
@@ -19,15 +19,17 @@ loadconfig
     exit 0
 }
 
-case $cmd in 
-     takeip|releaseip)
-       iface=$1
+case "$1" in 
+    takeip|releaseip)
+       iface=$2
        cat $CTDB_BASE/static-routes | egrep "^$iface " | while read IFACE DEST GW; do
            ip route add $DEST via $GW dev $IFACE >/dev/null 2>/dev/null
        done
-
        ;;
 
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
 exit 0
old mode 100644 (file)
new mode 100755 (executable)
index cf722d8..091a773
@@ -74,15 +74,15 @@ multipathd_check()
        fi
 }
 
-case $cmd in
-     startup)
+case "$1" in
+    startup)
        # create a state directory to keep/track the multipath device
        # state
        /bin/mkdir -p $CTDB_BASE/state/multipathd
        exit 0
        ;;
 
-     monitor)
+    monitor)
        multipathd_check
        [ "$?" = "0" ] || {
                echo 20.multipathd: monitoring of multipathing failed
@@ -90,7 +90,10 @@ case $cmd in
        }
        exit 0
        ;;
+
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
-# ignore unknown commands
 exit 0
old mode 100644 (file)
new mode 100755 (executable)
index a6515a9..73454d7
@@ -25,21 +25,21 @@ ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
 
-case $cmd in 
-     startup)
+case "$1" in 
+    startup)
        ctdb_service_start
         ;;
 
-     shutdown)
+    shutdown)
         ctdb_service_stop
         ;;
 
-     monitor)
+    monitor)
         ctdb_check_unix_socket ${CTDB_CLAMD_SOCKET} || exit $?
         ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
index 582604aae36417c6267581c994d762bbc9dd3c82..7ca7ba86332657899b94b89115c44a06988d5ffb 100755 (executable)
@@ -17,20 +17,20 @@ ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
 
-case $cmd in 
-     startup)
+case "$1" in 
+    startup)
        ctdb_service_start
        ;;
 
-     shutdown)
+    shutdown)
        ctdb_service_stop
        ;;
 
-     takeip|releaseip)
+    takeip|releaseip)
        ctdb_service_set_reconfigure
        ;;
 
-     recovered)
+    recovered)
        # if we have taken or released any ips we must 
        # restart vsftpd to ensure that all tcp connections are reset
        if ctdb_service_needs_reconfigure ; then
@@ -38,7 +38,7 @@ case $cmd in
        fi
        ;;
 
-     monitor)
+    monitor)
        if ctdb_service_needs_reconfigure ; then
            ctdb_service_reconfigure
            exit 0
@@ -55,8 +55,8 @@ case $cmd in
        fi      
        ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
index 7f9ee23f2476fb27fec9788f51a5e4d7758bd451..15a35ea1cfad455d68176face856bebd25559065 100755 (executable)
@@ -37,7 +37,7 @@ ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
 
-case $cmd in
+case "$1" in
     startup)
        ctdb_service_start
        ;;
@@ -59,8 +59,8 @@ case $cmd in
        fi
        ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
index 5b5aa1e1337fcd88d1603c8843d9646e9e6faa19..5c10b19ef08b55adb8ed9d40f1daecc8241b1832 100755 (executable)
@@ -196,7 +196,7 @@ periodic_cleanup() {
     smbstatus -np > /dev/null 2>&1 &
 }
 
-case $cmd in 
+case "$1" in 
      startup)
        ctdb_service_start
        ;;
@@ -251,10 +251,9 @@ case $cmd in
        }
        ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
-# ignore unknown commands
 exit 0
index 44ea674b7a5b31a0ab9b98671998f0c89caf7e66..4d5494a9a86913f4edc5717130e27d4c0fe951f5 100755 (executable)
@@ -31,7 +31,7 @@ loadconfig
 
 ctdb_start_stop_service
 
-case $cmd in 
+case "$1" in 
      startup)
        ctdb_service_start
        ;;
@@ -42,12 +42,12 @@ case $cmd in
 
      takeip)
        ctdb_service_set_reconfigure
-       touch $CTDB_BASE/state/statd/ip/$2
+       touch $CTDB_BASE/state/statd/ip/$3
        ;;
 
      releaseip)
        ctdb_service_set_reconfigure
-       /bin/rm -f $CTDB_BASE/state/statd/ip/$2
+       /bin/rm -f $CTDB_BASE/state/statd/ip/$3
        ;;
 
      recovered)
@@ -103,8 +103,8 @@ case $cmd in
        }
                ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
index e2bde52da612153b14c00985e7efd7279bb4315c..b717e2adcda0f0340eb64ebc8e9dbeaa59e45715 100755 (executable)
@@ -13,14 +13,14 @@ ctdb_start_stop_service
 
 [ -z "$NFS_TICKLE_SHARED_DIRECTORY" ] && exit 0
 
-case $cmd in 
+case "$1" in 
      startup)
        ctdb_service_start
        ;;
        
      takeip)
-       iface=$1
-       ip=$2
+       iface=$2
+       ip=$3
        # first send a grat arp, to ensure the client knows the updated
        # mac address for this IP
        ctdb gratiousarp $ip $iface
@@ -48,7 +48,9 @@ case $cmd in
                done
        ;;
 
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
-# ignore unknown commands
 exit 0
index 8cbf457eb4eb446420e9c5ed8c5e31a28561e8b3..a3cf040295c688d547608f1bfc7ece371c5f2844 100755 (executable)
@@ -12,8 +12,8 @@ ctdb_start_stop_service
        exit 0
 }
 
-case $cmd in 
-     recovered)
+case "$1" in 
+    recovered)
        # block the iscsi port
        iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
        
@@ -43,19 +43,18 @@ case $cmd in
 
        ;;
 
-     shutdown)
+    shutdown)
        # shutdown iscsi when ctdb goes down
        killall -9 tgtd >/dev/null 2>/dev/null
        ;;
 
-     monitor)
+    monitor)
        ctdb_check_tcp_ports 3260 || exit $?
        ;;
 
-    status)
-       ctdb_checkstatus || exit $?
+    *)
+       ctdb_standard_event_handler "$@"
        ;;
 esac
 
-# ignore unknown commands
 exit 0
index 3bc316fa6814c6b0013a4a60c5caf1c0e106ebff..3fbc57dba25b476b5890a7ff3750b6b2359da893 100755 (executable)
@@ -13,7 +13,7 @@ loadconfig ctdb
     exit 0
 }
 
-case $cmd in 
+case "$1" in 
      startup)
        ipvsadm -D -t $CTDB_LVS_PUBLIC_IP:0
        ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0
@@ -78,6 +78,9 @@ case $cmd in
        echo 1 > /proc/sys/net/ipv4/route/flush
        ;;
 
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
 exit 0
index a1201bfc5c20172c3bfe2649cef1d484a12abf41..7a47c8dd8166179f2b0c07bdf69167e1011b1ae1 100755 (executable)
@@ -9,12 +9,17 @@ loadconfig ctdb
 
 [ "$CTDB_RUN_TIMEOUT_MONITOR" = "yes" ] || exit 0
 
-case $cmd in
+case "$1" in
     monitor)
        TIMEOUT=$(ctdb listvars | awk '$1 == "EventScriptTimeout" {print $3}')
        echo "sleeping for $((TIMEOUT * 2)) seconds..."
        sleep $((TIMEOUT * 2))
        ;;
+
+
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
 exit 0
index 7265db92ef7b6aea5bdf17e2dba999e37ded7190..87026ac3f9effb5f61c96382c80d83feeeb52cb0 100644 (file)
@@ -586,6 +586,20 @@ ctdb_service_stop ()
     fi
 }
 
+ctdb_standard_event_handler ()
+{
+    case "$1" in
+       status)
+           ctdb_checkstatus
+           exit
+           ;;
+       setstatus)
+           ctdb_setstatus "$@"
+           exit
+           ;;
+    esac
+}
+
 ########################################################
 # load a site local config file
 ########################################################
@@ -600,21 +614,6 @@ ctdb_service_stop ()
        done
 }
 
-# A reasonable default is the basename of the eventscript.
-script_name="${0##*/}" # basename
-service_name="$script_name"
+script_name="${0##*/}"       # basename
+service_name="$script_name"  # default is just the script name
 service_fail_limit=1
-
-ctdb_event="$1" ; shift
-cmd="$ctdb_event"
-
-case "$ctdb_event" in
-    status)
-       ctdb_checkstatus
-       exit
-       ;;
-    setstatus)
-       ctdb_setstatus "$@"
-       exit
-       ;;
-esac