diff options
author | Martin Schwenke <martin@meltin.net> | 2009-12-01 17:43:47 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2009-12-01 17:43:47 +1100 |
commit | db25ca69e56ea7d8808e1ace9d9cc28a611aab0c (patch) | |
tree | fdff0d00aa1d438d0b1dce8c1025884e71f7294c | |
parent | ad431c352004c0fdf4714919872cac043e1618dc (diff) | |
download | samba-db25ca69e56ea7d8808e1ace9d9cc28a611aab0c.tar.gz |
Eventscript argument cleanups and introduction of ctdb_standard_event_handler.
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>
(This used to be ctdb commit 3d55408cbbb3bb71670b80f3dad5639ea0be5b5b)
-rwxr-xr-x | ctdb/config/ctdb.init | 2 | ||||
-rwxr-xr-x | ctdb/config/events.d/00.ctdb | 6 | ||||
-rwxr-xr-x | ctdb/config/events.d/01.reclock | 7 | ||||
-rwxr-xr-x | ctdb/config/events.d/10.interface | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | ctdb/config/events.d/11.natgw | 5 | ||||
-rwxr-xr-x | ctdb/config/events.d/11.routing | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | ctdb/config/events.d/20.multipathd | 11 | ||||
-rwxr-xr-x[-rw-r--r--] | ctdb/config/events.d/31.clamd | 12 | ||||
-rwxr-xr-x | ctdb/config/events.d/40.vsftpd | 16 | ||||
-rwxr-xr-x | ctdb/config/events.d/41.httpd | 6 | ||||
-rwxr-xr-x | ctdb/config/events.d/50.samba | 7 | ||||
-rwxr-xr-x | ctdb/config/events.d/60.nfs | 10 | ||||
-rwxr-xr-x | ctdb/config/events.d/61.nfstickle | 10 | ||||
-rwxr-xr-x | ctdb/config/events.d/70.iscsi | 13 | ||||
-rwxr-xr-x | ctdb/config/events.d/91.lvs | 5 | ||||
-rwxr-xr-x | ctdb/config/events.d/99.timeout | 7 | ||||
-rw-r--r-- | ctdb/config/functions | 33 |
17 files changed, 101 insertions, 81 deletions
diff --git a/ctdb/config/ctdb.init b/ctdb/config/ctdb.init index 4bd570d343a..67747fd149d 100755 --- a/ctdb/config/ctdb.init +++ b/ctdb/config/ctdb.init @@ -250,7 +250,7 @@ status() { } -case "$cmd" in +case "$1" in start) start ;; diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb index f2ec5e85b83..bad129f538e 100755 --- a/ctdb/config/events.d/00.ctdb +++ b/ctdb/config/events.d/00.ctdb @@ -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 diff --git a/ctdb/config/events.d/01.reclock b/ctdb/config/events.d/01.reclock index 1b6cbf09e44..919d29697fb 100755 --- a/ctdb/config/events.d/01.reclock +++ b/ctdb/config/events.d/01.reclock @@ -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 diff --git a/ctdb/config/events.d/10.interface b/ctdb/config/events.d/10.interface index da6d903d53b..e24cc36a164 100755 --- a/ctdb/config/events.d/10.interface +++ b/ctdb/config/events.d/10.interface @@ -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 diff --git a/ctdb/config/events.d/11.natgw b/ctdb/config/events.d/11.natgw index 3a350942f9c..ee7b4f9c63b 100644..100755 --- a/ctdb/config/events.d/11.natgw +++ b/ctdb/config/events.d/11.natgw @@ -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 diff --git a/ctdb/config/events.d/11.routing b/ctdb/config/events.d/11.routing index cb34e417a8f..c265c382d0c 100755 --- a/ctdb/config/events.d/11.routing +++ b/ctdb/config/events.d/11.routing @@ -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 diff --git a/ctdb/config/events.d/20.multipathd b/ctdb/config/events.d/20.multipathd index cf722d8ce98..091a7739b69 100644..100755 --- a/ctdb/config/events.d/20.multipathd +++ b/ctdb/config/events.d/20.multipathd @@ -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 diff --git a/ctdb/config/events.d/31.clamd b/ctdb/config/events.d/31.clamd index a6515a96d7e..73454d7c53d 100644..100755 --- a/ctdb/config/events.d/31.clamd +++ b/ctdb/config/events.d/31.clamd @@ -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 diff --git a/ctdb/config/events.d/40.vsftpd b/ctdb/config/events.d/40.vsftpd index 582604aae36..7ca7ba86332 100755 --- a/ctdb/config/events.d/40.vsftpd +++ b/ctdb/config/events.d/40.vsftpd @@ -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 diff --git a/ctdb/config/events.d/41.httpd b/ctdb/config/events.d/41.httpd index 7f9ee23f247..15a35ea1cfa 100755 --- a/ctdb/config/events.d/41.httpd +++ b/ctdb/config/events.d/41.httpd @@ -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 diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba index 5b5aa1e1337..5c10b19ef08 100755 --- a/ctdb/config/events.d/50.samba +++ b/ctdb/config/events.d/50.samba @@ -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 diff --git a/ctdb/config/events.d/60.nfs b/ctdb/config/events.d/60.nfs index 44ea674b7a5..4d5494a9a86 100755 --- a/ctdb/config/events.d/60.nfs +++ b/ctdb/config/events.d/60.nfs @@ -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 diff --git a/ctdb/config/events.d/61.nfstickle b/ctdb/config/events.d/61.nfstickle index e2bde52da61..b717e2adcda 100755 --- a/ctdb/config/events.d/61.nfstickle +++ b/ctdb/config/events.d/61.nfstickle @@ -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 diff --git a/ctdb/config/events.d/70.iscsi b/ctdb/config/events.d/70.iscsi index 8cbf457eb4e..a3cf040295c 100755 --- a/ctdb/config/events.d/70.iscsi +++ b/ctdb/config/events.d/70.iscsi @@ -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 diff --git a/ctdb/config/events.d/91.lvs b/ctdb/config/events.d/91.lvs index 3bc316fa681..3fbc57dba25 100755 --- a/ctdb/config/events.d/91.lvs +++ b/ctdb/config/events.d/91.lvs @@ -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 diff --git a/ctdb/config/events.d/99.timeout b/ctdb/config/events.d/99.timeout index a1201bfc5c2..7a47c8dd816 100755 --- a/ctdb/config/events.d/99.timeout +++ b/ctdb/config/events.d/99.timeout @@ -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 diff --git a/ctdb/config/functions b/ctdb/config/functions index 7265db92ef7..87026ac3f9e 100644 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -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 |