mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
Merge remote branch 'martins/eventscripts'
(This used to be ctdb commit 1bb814f012cb6ce436f8748b06602e8d6fae8822)
This commit is contained in:
commit
3224be80ba
@ -295,6 +295,10 @@ CTDB_DEBUGLEVEL=ERR
|
||||
# above 90%
|
||||
# CTDB_CHECK_FS_USE="/:90 /var:90"
|
||||
|
||||
# Should CTDB automatically start and stop services when it is told to
|
||||
# newly manage or no longer manage them?
|
||||
CTDB_SERVICE_AUTOSTARTSTOP=yes
|
||||
|
||||
#
|
||||
#
|
||||
# set any default tuning options for ctdb
|
||||
|
@ -35,6 +35,8 @@ update_config_from_tdb() {
|
||||
fi
|
||||
}
|
||||
|
||||
ctdb_check_args "$@"
|
||||
|
||||
case "$1" in
|
||||
init)
|
||||
# make sure we have a blank state directory for the scripts to work with
|
||||
|
@ -129,6 +129,8 @@ monitor_interfaces()
|
||||
return 1
|
||||
}
|
||||
|
||||
ctdb_check_args "$@"
|
||||
|
||||
case "$1" in
|
||||
#############################
|
||||
# called when ctdbd starts up
|
||||
@ -158,10 +160,6 @@ case "$1" in
|
||||
################################################
|
||||
# called when ctdbd wants to claim an IP address
|
||||
takeip)
|
||||
if [ $# != 4 ]; then
|
||||
echo "ERROR: must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
iface=$2
|
||||
ip=$3
|
||||
maskbits=$4
|
||||
@ -181,11 +179,6 @@ case "$1" in
|
||||
##################################################
|
||||
# called when ctdbd wants to release an IP address
|
||||
releaseip)
|
||||
if [ $# != 4 ]; then
|
||||
echo "ERROR: must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# releasing an IP is a bit more complex than it seems. Once the IP
|
||||
# is released, any open tcp connections to that IP on this host will end
|
||||
# up being stuck. Some of them (such as NFS connections) will be unkillable
|
||||
@ -220,11 +213,6 @@ case "$1" in
|
||||
##################################################
|
||||
# called when ctdbd wants to update an IP address
|
||||
updateip)
|
||||
if [ $# != 5 ]; then
|
||||
echo "ERROR: must supply old interface, new interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# moving an IP is a bit more complex than it seems.
|
||||
# First we drop all traffic on the old interface.
|
||||
# Then we try to add the ip to the new interface and before
|
||||
|
@ -326,6 +326,8 @@ setup_per_ip_routing()
|
||||
return $?;
|
||||
}
|
||||
|
||||
ctdb_check_args "$@"
|
||||
|
||||
case "$1" in
|
||||
#############################
|
||||
# called when ctdbd starts up
|
||||
@ -368,10 +370,6 @@ case "$1" in
|
||||
################################################
|
||||
# called when ctdbd wants to claim an IP address
|
||||
takeip)
|
||||
if [ $# != 4 ]; then
|
||||
echo "must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
iface=$2
|
||||
ip=$3
|
||||
maskbits=$4
|
||||
@ -410,10 +408,6 @@ case "$1" in
|
||||
################################################
|
||||
# called when ctdbd wants to claim an IP address
|
||||
updateip)
|
||||
if [ $# != 5 ]; then
|
||||
echo "must supply old interface, new interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
oiface=$2
|
||||
niface=$3
|
||||
ip=$4
|
||||
@ -455,11 +449,6 @@ case "$1" in
|
||||
##################################################
|
||||
# called when ctdbd wants to release an IP address
|
||||
releaseip)
|
||||
if [ $# != 4 ]; then
|
||||
echo "must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
iface=$2
|
||||
ip=$3
|
||||
maskbits=$4
|
||||
|
@ -70,6 +70,7 @@ case "$1" in
|
||||
[ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
|
||||
exportfs -v | grep '^/' |
|
||||
sed -r -e 's@[[:space:]]+[^[:space:]()]+\([^[:space:]()]+\)$@@' |
|
||||
sort -u |
|
||||
ctdb_check_directories
|
||||
} || exit $?
|
||||
|
||||
|
@ -82,6 +82,26 @@ debug ()
|
||||
fi
|
||||
}
|
||||
|
||||
##############################################################
|
||||
# check number of args for different events
|
||||
ctdb_check_args ()
|
||||
{
|
||||
case "$1" in
|
||||
takeip|releaseip)
|
||||
if [ $# != 4 ]; then
|
||||
echo "ERROR: must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
updateip)
|
||||
if [ $# != 5 ]; then
|
||||
echo "ERROR: must supply old interface, new interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
##############################################################
|
||||
# determine on what type of system (init style) we are running
|
||||
detect_init_style() {
|
||||
@ -358,6 +378,7 @@ ctdb_check_tcp_ports()
|
||||
ctdb_check_tcp_ports_$_c "$@"
|
||||
case "$?" in
|
||||
0)
|
||||
_ctdb_check_tcp_common
|
||||
rm -f "$_ctdb_service_started_file"
|
||||
return 0
|
||||
;;
|
||||
@ -466,7 +487,8 @@ ctdb_check_tcp_ports_ctdb ()
|
||||
for _p ; do # process each function argument (port)
|
||||
_cmd="ctdb checktcpport $_p"
|
||||
_out=$($_cmd 2>&1)
|
||||
case "$?" in
|
||||
_ret=$?
|
||||
case "$_ret" in
|
||||
0)
|
||||
ctdb_check_tcp_ports_debug="\"$_cmd\" was able to bind to port"
|
||||
return 1
|
||||
@ -476,7 +498,7 @@ ctdb_check_tcp_ports_ctdb ()
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
ctdb_check_tcp_ports_debug="$_cmd (exited with $?) with output:
|
||||
ctdb_check_tcp_ports_debug="$_cmd (exited with $_ret) with output:
|
||||
$_out"
|
||||
# assume not implemented
|
||||
return 127
|
||||
@ -992,7 +1014,7 @@ ctdb_service_unset_reconfigure ()
|
||||
|
||||
ctdb_service_reconfigure ()
|
||||
{
|
||||
echo "Reconfiguring service \"$service_name\"..."
|
||||
echo "Reconfiguring service \"$@\"..."
|
||||
ctdb_service_unset_reconfigure "$@"
|
||||
service_reconfigure "$@" || return $?
|
||||
ctdb_counter_init "$@"
|
||||
@ -1004,28 +1026,129 @@ service_reconfigure ()
|
||||
service "${1:-$service_name}" restart
|
||||
}
|
||||
|
||||
ctdb_reconfigure_try_lock ()
|
||||
{
|
||||
|
||||
_ctdb_service_reconfigure_common "$@"
|
||||
_lock="${_d}/reconfigure_lock"
|
||||
touch "$_lock"
|
||||
|
||||
(
|
||||
flock 0
|
||||
# This is overkill but will work if we need to extend this to
|
||||
# allow certain events to run multiple times in parallel
|
||||
# (e.g. takeip) and write multiple PIDs to the file.
|
||||
read _locker_event
|
||||
if [ -n "$_locker_event" ] ; then
|
||||
while read _pid ; do
|
||||
if [ -n "$_pid" -a "$_pid" != $$ ] && \
|
||||
kill -0 "$_pid" 2>/dev/null ; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
printf "%s\n%s\n" "$event_name" $$ >"$_lock"
|
||||
exit 0
|
||||
) <"$_lock"
|
||||
}
|
||||
|
||||
ctdb_replay_monitor_status ()
|
||||
{
|
||||
echo "Replaying previous status for this script due to reconfigure..."
|
||||
# Leading colon (':') is missing in some versions...
|
||||
_out=$(ctdb scriptstatus -Y | grep -E "^:?monitor:${script_name}:")
|
||||
# Output looks like this:
|
||||
# :monitor:60.nfs:1:ERROR:1314764004.030861:1314764004.035514:foo bar:
|
||||
# This is the cheapest way of getting fields in the middle.
|
||||
set -- $(IFS=":" ; echo $_out)
|
||||
_code="$3"
|
||||
_status="$4"
|
||||
# The error output field can include colons so we'll try to
|
||||
# preserve them. The weak checking at the beginning tries to make
|
||||
# this work for both broken (no leading ':') and fixed output.
|
||||
_out="${_out%:}"
|
||||
_err_out="${_out#*monitor:${script_name}:*:*:*:*:}"
|
||||
case "$_status" in
|
||||
OK) : ;; # Do nothing special.
|
||||
TIMEDOUT)
|
||||
# Recast this as an error, since we can't exit with the
|
||||
# correct negative number.
|
||||
_code=1
|
||||
_err_out="[Replay of TIMEDOUT scriptstatus - note incorrect return code.] ${_err_out}"
|
||||
;;
|
||||
DISABLED)
|
||||
# Recast this as an OK, since we can't exit with the
|
||||
# correct negative number.
|
||||
_code=0
|
||||
_err_out="[Replay of DISABLED scriptstatus - note incorrect return code.] ${_err_out}"
|
||||
;;
|
||||
*) : ;; # Must be ERROR, do nothing special.
|
||||
esac
|
||||
echo "$_err_out"
|
||||
exit $_code
|
||||
}
|
||||
|
||||
ctdb_service_check_reconfigure ()
|
||||
{
|
||||
# Only do this for certain events.
|
||||
[ -n "$1" ] || set -- "$service_name"
|
||||
|
||||
# We only care about some events in this function. For others we
|
||||
# return now.
|
||||
case "$event_name" in
|
||||
monitor|ipreallocated) : ;;
|
||||
*) return 0
|
||||
monitor|ipreallocated|reconfigure) : ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
|
||||
if ctdb_service_needs_reconfigure "$@" ; then
|
||||
ctdb_service_reconfigure "$@"
|
||||
|
||||
# Fall through to non-monitor events.
|
||||
[ "$event_name" = "monitor" ] || return 0
|
||||
|
||||
# We don't want to proceed with the rest of the monitor event
|
||||
# here, so we exit. However, if we exit 0 then, if the
|
||||
# service was previously broken, we might return a false
|
||||
# positive. So we simply retrieve the status of this script
|
||||
# from the previous monitor loop and exit with that status.
|
||||
ctdb scriptstatus | \
|
||||
grep -q -E "^${script_name}[[:space:]]+Status:OK[[:space:]]"
|
||||
exit $?
|
||||
if ctdb_reconfigure_try_lock "$@" ; then
|
||||
# No events covered by this function are running, so proceed
|
||||
# with gay abandon.
|
||||
case "$event_name" in
|
||||
reconfigure)
|
||||
(ctdb_service_reconfigure "$@")
|
||||
exit $?
|
||||
;;
|
||||
ipreallocated)
|
||||
if ctdb_service_needs_reconfigure "$@" ; then
|
||||
ctdb_service_reconfigure "$@"
|
||||
fi
|
||||
;;
|
||||
monitor)
|
||||
if ctdb_service_needs_reconfigure "$@" ; then
|
||||
ctdb_service_reconfigure "$@"
|
||||
# Given that the reconfigure might not have
|
||||
# resulted in the service being stable yet, we
|
||||
# replay the previous status since that's the best
|
||||
# information we have.
|
||||
ctdb_replay_monitor_status
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# Somebody else is running an event we don't want to collide
|
||||
# with. We proceed with caution.
|
||||
case "$event_name" in
|
||||
reconfigure)
|
||||
# Tell whoever called us to retry.
|
||||
exit 2
|
||||
;;
|
||||
ipreallocated)
|
||||
# Defer any scheduled reconfigure and just run the
|
||||
# rest of the ipreallocated event, as per the
|
||||
# eventscript. There's an assumption here that the
|
||||
# event doesn't depend on any scheduled reconfigure.
|
||||
# This is true in the current code.
|
||||
return 0
|
||||
;;
|
||||
monitor)
|
||||
# There is most likely a reconfigure in progress so
|
||||
# the service is possibly unstable. As above, we
|
||||
# defer any scheduled reconfigured. We also replay
|
||||
# the previous monitor status since that's the best
|
||||
# information we have.
|
||||
ctdb_replay_monitor_status
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
@ -1072,6 +1195,9 @@ is_ctdb_managed_service ()
|
||||
|
||||
ctdb_start_stop_service ()
|
||||
{
|
||||
# Do nothing unless configured to...
|
||||
[ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] || return 0
|
||||
|
||||
_service_name="${1:-${service_name}}"
|
||||
|
||||
[ "$event_name" = "monitor" ] || return 0
|
||||
|
Loading…
Reference in New Issue
Block a user