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>
}
-case "$cmd" in
+case "$1" in
start)
start
;;
. $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
ctdb shutdown
}
}
+
+ *)
+ ctdb_standard_event_handler "$@"
+ ;;
esac
# all OK
. $CTDB_BASE/functions
loadconfig
-case $cmd in
+case "$1" in
startup)
ctdb_counter_init
;;
ctdb_check_counter_limit 3 quiet
;;
- status)
- ctdb_checkstatus || exit $?
+
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
exit 0
}
-case $cmd in
+case "$1" in
#############################
# called when ctdbd starts up
startup)
################################################
# 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 || {
##################################################
# 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
# 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
esac
done
;;
- status)
- ctdb_checkstatus || exit $?
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
}
-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
delete_all
;;
+ *)
+ ctdb_standard_event_handler "@"
+ ;;
esac
exit 0
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
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
}
exit 0
;;
+
+ *)
+ ctdb_standard_event_handler "$@"
+ ;;
esac
-# ignore unknown commands
exit 0
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
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
fi
;;
- monitor)
+ monitor)
if ctdb_service_needs_reconfigure ; then
ctdb_service_reconfigure
exit 0
fi
;;
- status)
- ctdb_checkstatus || exit $?
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
is_ctdb_managed_service || exit 0
-case $cmd in
+case "$1" in
startup)
ctdb_service_start
;;
fi
;;
- status)
- ctdb_checkstatus || exit $?
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
smbstatus -np > /dev/null 2>&1 &
}
-case $cmd in
+case "$1" in
startup)
ctdb_service_start
;;
}
;;
- status)
- ctdb_checkstatus || exit $?
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
-# ignore unknown commands
exit 0
ctdb_start_stop_service
-case $cmd in
+case "$1" in
startup)
ctdb_service_start
;;
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)
}
;;
- status)
- ctdb_checkstatus || exit $?
+ *)
+ ctdb_standard_event_handler "$@"
;;
esac
[ -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
done
;;
+ *)
+ ctdb_standard_event_handler "$@"
+ ;;
esac
-# ignore unknown commands
exit 0
exit 0
}
-case $cmd in
- recovered)
+case "$1" in
+ recovered)
# block the iscsi port
iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
;;
- 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
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
echo 1 > /proc/sys/net/ipv4/route/flush
;;
+ *)
+ ctdb_standard_event_handler "$@"
+ ;;
esac
exit 0
[ "$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
fi
}
+ctdb_standard_event_handler ()
+{
+ case "$1" in
+ status)
+ ctdb_checkstatus
+ exit
+ ;;
+ setstatus)
+ ctdb_setstatus "$@"
+ exit
+ ;;
+ esac
+}
+
########################################################
# load a site local config file
########################################################
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