1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

More eventscript cleanups. Initial smoke testing seems OK.

Apart from lots of cleanup work, this also fixes a bug where the share
checks didn't used to cope with directory names containing spaces.
The previous commit also loaded the config incorrectly.

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 3c93336ab92c2e4829ff4dc360045bfa6df21d50)
This commit is contained in:
Martin Schwenke 2009-11-20 16:45:36 +11:00 committed by Andrew Tridgell
parent 3188df4a88
commit 1edcb89948
3 changed files with 63 additions and 133 deletions

View File

@ -179,6 +179,14 @@ check_ctdb_manages_winbind() {
}
}
list_samba_shares ()
{
testparm_cat |
sed -n -e 's@^[[:space:]]*path[[:space:]]*=[[:space:]]@@p' |
sed -e 's/"//g'
}
###########################
# periodic cleanup function
periodic_cleanup() {
@ -221,12 +229,12 @@ case $cmd in
}
}
smb_dirs=`testparm_cat | egrep '^[[:space:]]*path = ' | cut -d= -f2`
ctdb_check_directories_probe "Samba" $smb_dirs || {
list_samba_shares |
ctdb_check_directories_probe || {
testparm_foreground_update
smb_dirs=`testparm_cat | egrep '^[[:space:]]*path = ' | cut -d= -f2`
ctdb_check_directories "Samba" $smb_dirs
}
list_samba_shares |
ctdb_check_directories
} || exit $?
}
smb_ports="$CTDB_SAMBA_CHECK_PORTS"

View File

@ -81,13 +81,15 @@ case $cmd in
# and that its directories are available
[ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
nfs_dirs=$(exportfs | grep -v '^#' | grep '^/' | awk {'print $1;'})
ctdb_check_directories "nfs" $nfs_dirs
}
exportfs | grep -v '^#' | grep '^/' |
sed -e 's/[[:space:]]*[^[:space:]]*$//' |
ctdb_check_directories
} || exit $?
# check that lockd responds to rpc requests
ctdb_check_rpc "lockd" 100021 1
ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
echo "$STATD_SHARED_DIRECTORY" | ctdb_check_directories "statd" || \
exit $?
# mount needs special handling since it is sometimes not started
# correctly on RHEL5

View File

@ -5,24 +5,24 @@ PATH=/bin:/usr/bin:/usr/sbin:/sbin:$PATH
#######################################
# pull in a system config file, if any
loadconfig() {
name="$1"
if [ "$name" != "ctdb" ] ; then
if [ "$1" != "ctdb" ] ; then
loadconfig "ctdb"
fi
if [ -z "$name" ] ; then
if [ -z "$1" ] ; then
foo="${service_config:-${service_name}}"
if [ -n "$foo" ] ; then
loadconfig "$foo"
fi
fi
if [ -f /etc/sysconfig/$name ]; then
. /etc/sysconfig/$name
elif [ -f /etc/default/$name ]; then
. /etc/default/$name
elif [ -f $CTDB_BASE/sysconfig/$name ]; then
. $CTDB_BASE/sysconfig/$name
if [ -f /etc/sysconfig/$1 ]; then
. /etc/sysconfig/$1
elif [ -f /etc/default/$1 ]; then
. /etc/default/$1
elif [ -f $CTDB_BASE/sysconfig/$1 ]; then
. $CTDB_BASE/sysconfig/$1
fi
}
@ -48,7 +48,7 @@ service() {
_op="$2"
# do nothing, when no service was specified
test "x$_service_name" = "x" && return
[ -z "$_service_name" ] && return
if [ -x /sbin/service ]; then
/sbin/service "$_service_name" "$_op"
@ -62,6 +62,9 @@ service() {
######################################################
# simulate /sbin/service (niced) on platforms that don't have it
nice_service() {
# do nothing, when no service was specified
[ -z "$1" ] && return
nice service "$@"
}
@ -124,44 +127,17 @@ ctdb_wait_tcp_ports() {
}
######################################################
# wait for a set of directories
# usage: ctdb_wait_directories SERVICE_NAME <directories...>
######################################################
ctdb_wait_directories() {
service_name="$1"
shift
wait_dirs="$*"
[ -z "$wait_dirs" ] && return;
all_ok=0
echo "Waiting for local directories for $service_name"
while [ $all_ok -eq 0 ]; do
all_ok=1
for d in $wait_dirs; do
[ -d $d ] || all_ok=0
done
[ $all_ok -eq 1 ] || sleep 1
ctdb status > /dev/null 2>&1 || {
echo "ctdb daemon has died. Exiting directory wait for $service_name"
exit 1
}
done
echo "Local directories for $service_name are available"
}
######################################################
# check that a rpc server is registered with portmap
# and responding to requests
# usage: ctdb_check_rpc SERVICE_NAME PROGNUM VERSION
######################################################
ctdb_check_rpc() {
service_name="$1"
progname="$1"
prognum="$2"
version="$3"
rpcinfo -u localhost $prognum $version > /dev/null || {
echo "ERROR: $service_name not responding to rpc requests"
echo "ERROR: $progname not responding to rpc requests"
exit 1
}
}
@ -172,9 +148,7 @@ ctdb_check_rpc() {
# usage: ctdb_check_directories_probe SERVICE_NAME <directories...>
######################################################
ctdb_check_directories_probe() {
service_name="$1"
shift
for d ; do
while IFS="" read d ; do
case "$d" in
*%*)
continue
@ -183,7 +157,6 @@ ctdb_check_directories_probe() {
[ -d "$d" ] || return 1
esac
done
return 0
}
######################################################
@ -191,58 +164,26 @@ ctdb_check_directories_probe() {
# usage: ctdb_check_directories SERVICE_NAME <directories...>
######################################################
ctdb_check_directories() {
# Note: ctdb_check_directories_probe sets both $service_name and $d.
ctdb_check_directories_probe "$@" || {
echo "ERROR: $service_name directory $d not available"
n="${1:-${service_name}}"
ctdb_check_directories_probe || {
echo "ERROR: $n directory \"$d\" not available"
exit 1
}
}
######################################################
# check a set of tcp ports
# usage: ctdb_check_tcp_ports SERVICE_NAME <ports...>
# usage: ctdb_check_tcp_ports <ports...>
######################################################
ctdb_check_tcp_ports() {
[ -z "$1" ] && return;
# check availability of netcat or netstat first
NETCAT=""
NETSTAT=""
if [ -x /usr/bin/netstat ]; then
NETSTAT=/usr/bin/netstat
elif [ -x /bin/netstat ]; then
NETSTAT=/bin/netstat
elif [ -x /usr/bin/netcat ]; then
NETCAT=/usr/bin/netcat
elif [ -x /bin/netcat ]; then
NETCAT=/bin/netcat
elif [ -x /usr/bin/nc ]; then
NETCAT=/usr/bin/nc
elif [ -x /bin/nc ]; then
NETCAT=/bin/nc
fi
for p ; do
all_ok=1
if [ "x${NETCAT}" != "x" ]; then
${NETCAT} -z 127.0.0.1 $p > /dev/null || all_ok=0
elif [ "x${NETSTAT}" != "x" ]; then
if ! ${NETSTAT} -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ; then
if ! ${NETSTAT} -a -n | egrep ":::$p .*LISTEN" > /dev/null ; then
all_ok=0
fi
fi
else
echo "ERROR: neither netcat (or nc) nor netstat found!"
echo "ERROR: can't monitor ${service_name} tcp port ${p}"
all_ok=0
fi
[ $all_ok -eq 1 ] || {
if ! netstat -a -t -n | grep -q "0\.0\.0\.0:$p .*LISTEN" ; then
if ! netstat -a -t -n | grep -q ":::$p .*LISTEN" ; then
echo "ERROR: $service_name tcp port $p is not responding"
return 1
}
fi
fi
done
}
@ -252,33 +193,12 @@ ctdb_check_tcp_ports() {
######################################################
ctdb_check_unix_socket() {
socket_path="$1"
[ -z "$socket_path" ] && return;
[ -z "$socket_path" ] && return
# check availability of netstat first
NETSTAT=""
if [ -x $(type -p netstat) ]; then
NETSTAT=$(type -p netstat)
elif [ -x /usr/bin/netstat ]; then
NETSTAT=/usr/bin/netstat
elif [ -x /bin/netstat ]; then
NETSTAT=/bin/netstat
fi
all_ok=1
if [ "x$NETSTAT" != "x" ]; then
if $NETSTAT -l -a -n | grep -qE "^unix.*LISTEN.*${socket_path}$"; then
all_ok=1
else
all_ok=0
fi
else
[ -S ${socket_path} ] && all_ok=1 || all_ok=0
fi
[ $all_ok -eq 1 ] || {
if ! netstat --unix -a -n | grep -q "^unix.*LISTEN.*${socket_path}$"; then
echo "ERROR: $service_name socket $socket_path not found"
return 1
}
fi
}
######################################################