[SCM] CTDB repository - branch status-test-2 updated - ctdb-1.0.104-36-gd3e7407

Ronnie Sahlberg sahlberg at samba.org
Wed Nov 25 19:44:22 MST 2009


The branch, status-test-2 has been updated
       via  d3e7407dc9854ec358d081777c5450ec68b17862 (commit)
       via  a2830594ebeb54eb51ff90999cb12370aeec6e8b (commit)
       via  517e9d9b188b18dffc712a8fecddb41540d27b8d (commit)
       via  5d97c07be13a8209a81dfc8f73e49371949e4dc3 (commit)
       via  3c93336ab92c2e4829ff4dc360045bfa6df21d50 (commit)
       via  2e60749de3714239224cc04170a9aeeee158153f (commit)
       via  66b22980b14601f29fe8cc64bd8f29883c7ca1c0 (commit)
       via  a6d353519932eee48f9241ad8887b692882906c9 (commit)
       via  b0648c7f08eba87ec3c9714e2525c9b621bfb4ef (commit)
       via  834c93b3e1b8f4151b8a2cd82c2dd8bacc17f66c (commit)
       via  470822b329f9d3ca9bef518b56e9ce28d5fedda2 (commit)
       via  fe8027309c1f7b987cd368fa98f9b28741baa786 (commit)
       via  e7d57d7ae678b24dab3364a348838c6a3398942c (commit)
       via  20b15de068d042b292725945927ceda1b01d07c0 (commit)
       via  c715746c2f40eb9b21dbf011d16f1f1b0b53fdf9 (commit)
       via  c5f798116bf3b7954e23c7267b056ee1f5560f45 (commit)
       via  35a60a63a9b5c7d98dde514ae552239506b691c9 (commit)
      from  1d24a3869fe89fc9a109fd9e9b69df5fc665a5f6 (commit)

http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=status-test-2


- Log -----------------------------------------------------------------
commit d3e7407dc9854ec358d081777c5450ec68b17862
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Nov 26 13:42:12 2009 +1100

    resolve some conflicts from merging from martins branch

commit a2830594ebeb54eb51ff90999cb12370aeec6e8b
Merge: 2e60749de3714239224cc04170a9aeeee158153f 517e9d9b188b18dffc712a8fecddb41540d27b8d
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Nov 26 10:49:47 2009 +1100

    Merge commit 'martins-svart/status-test-2' into status-test
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 517e9d9b188b18dffc712a8fecddb41540d27b8d
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Nov 25 16:42:14 2009 +1100

    Event scripts: use $script_name rather than $service name for status.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 5d97c07be13a8209a81dfc8f73e49371949e4dc3
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Nov 25 16:34:49 2009 +1100

    Event scripts: Respect CTDB_MANAGES_NFS and add function log_status_cat.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 3c93336ab92c2e4829ff4dc360045bfa6df21d50
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Nov 20 16:45:36 2009 +1100

    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 at meltin.net>

commit 2e60749de3714239224cc04170a9aeeee158153f
Merge: 35a60a63a9b5c7d98dde514ae552239506b691c9 66b22980b14601f29fe8cc64bd8f29883c7ca1c0
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 24 16:14:54 2009 +1100

    Merge commit 'origin/status-test' into status-test

commit 35a60a63a9b5c7d98dde514ae552239506b691c9
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Nov 20 16:45:36 2009 +1100

    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 at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 config/events.d/50.samba |   20 ++++--
 config/events.d/60.nfs   |   10 ++-
 config/functions         |  185 ++++++++++++++--------------------------------
 server/eventscript.c     |    3 +-
 4 files changed, 78 insertions(+), 140 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/events.d/50.samba b/config/events.d/50.samba
index e285347..5b5aa1e 100755
--- a/config/events.d/50.samba
+++ b/config/events.d/50.samba
@@ -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() {
@@ -220,13 +228,13 @@ case $cmd in
 				exit 1
 			    }
 			}
-
-			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"
diff --git a/config/events.d/60.nfs b/config/events.d/60.nfs
index f6f02e5..44ea674 100755
--- a/config/events.d/60.nfs
+++ b/config/events.d/60.nfs
@@ -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
diff --git a/config/functions b/config/functions
index 2d60cb4..93b50af 100644
--- a/config/functions
+++ b/config/functions
@@ -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,18 +148,15 @@ ctdb_check_rpc() {
 # usage: ctdb_check_directories_probe SERVICE_NAME <directories...>
 ######################################################
 ctdb_check_directories_probe() {
-  service_name="$1"
-  shift
-  for d ; do
-      case "$d" in
-	  *%*)
-	      continue
-	      ;;
-	  *)
-	      [ -d "$d" ] || return 1
-      esac
-  done
-  return 0
+    while IFS="" read d ; do
+	case "$d" in
+	    *%*)
+		continue
+		;;
+	    *)
+		[ -d "$d" ] || return 1
+	esac
+    done
 }
 
 ######################################################
@@ -191,59 +164,27 @@ 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"
-      exit 1
-  }
+    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 ] || {
-	  echo "ERROR: $service_name tcp port $p is not responding"
-	  return 1
-      }
-  done
+    for p ; do
+	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
 }
 
 ######################################################
@@ -251,34 +192,13 @@ ctdb_check_tcp_ports() {
 # usage: ctdb_check_unix_socket SERVICE_NAME <socket_path>
 ######################################################
 ctdb_check_unix_socket() {
-  socket_path="$1"
-  [ -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
+    socket_path="$1"
+    [ -z "$socket_path" ] && return
 
-  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
+    if ! netstat --unix -a -n | grep -q "^unix.*LISTEN.*${socket_path}$"; then
+        echo "ERROR: $service_name socket $socket_path not found"
+        return 1
     fi
-    else
-    [ -S ${socket_path} ] && all_ok=1 || all_ok=0
-  fi
-
-  [ $all_ok -eq 1 ] || {
-    echo "ERROR: $service_name socket $socket_path not found"
-    return 1
-  }
 }
 
 ######################################################
@@ -539,13 +459,18 @@ ctdb_status_dir="$ctdb_spool_dir/status"
 ctdb_fail_dir="$ctdb_spool_dir/failcount"
 ctdb_active_dir="$ctdb_spool_dir/active"
 
+log_status_cat ()
+{
+    echo "node is \"$1\", problem with \"${script_name}\": $(cat $2)"
+}
+
 ctdb_checkstatus ()
 {
-    if [ -r "$ctdb_status_dir/$service_name/unhealthy" ] ; then
-	log_status_cat "unhealthy" "$ctdb_status_dir/$service_name/unhealthy"
+    if [ -r "$ctdb_status_dir/$script_name/unhealthy" ] ; then
+	log_status_cat "unhealthy" "$ctdb_status_dir/$script_name/unhealthy"
 	return 1
-    elif [ -r "$ctdb_status_dir/$service_name/banned" ] ; then
-	log_status_cat "banned" "$ctdb_status_dir/$service_name/banned"
+    elif [ -r "$ctdb_status_dir/$script_name/banned" ] ; then
+	log_status_cat "banned" "$ctdb_status_dir/$script_name/banned"
 	return 2
     else
 	return 0
@@ -554,7 +479,7 @@ ctdb_checkstatus ()
 
 ctdb_setstatus ()
 {
-    d="$ctdb_status_dir/$service_name"
+    d="$ctdb_status_dir/$script_name"
     case "$1" in
 	unhealthy|banned)
 	    mkdir -p "$d"
@@ -614,6 +539,7 @@ is_ctdb_managed_service ()
     ctdb_compat_managed_service "$CTDB_MANAGES_HTTPD"    "httpd"
     ctdb_compat_managed_service "$CTDB_MANAGES_ISCSI"    "iscsi"
     ctdb_compat_managed_service "$CTDB_MANAGES_CLAMD"    "clamd"
+    ctdb_compat_managed_service "$CTDB_MANAGES_NFS"      "nfs"
 
     # Returns 0 if "<space>$service_name<space>" appears in $t
     [ "${t#* ${service_name} }" != "${t}" ]
@@ -675,7 +601,8 @@ ctdb_service_stop ()
 }
 
 # A reasonable default is the basename of the eventscript.
-service_name="${0##*/}" # basename
+script_name="${0##*/}" # basename
+service_name="$script_name"
 service_fail_limit=1
 
 ctdb_event="$1" ; shift
diff --git a/server/eventscript.c b/server/eventscript.c
index 70674a0..a1ac36e 100644
--- a/server/eventscript.c
+++ b/server/eventscript.c
@@ -714,7 +714,7 @@ static void ctdb_event_script_timeout(struct event_context *ev, struct timed_eve
 			talloc_free(ctdb->last_monitor_status_ctx);
 			ctdb->last_monitor_status_ctx = NULL;
 		}
-		ctdb->last_monitor_status_ctx = ctdb->current_monitor_status_ctx;
+		ctdb->last_monitor_status_ctx = talloc_steal(ctdb, ctdb->current_monitor_status_ctx);
 		ctdb->current_monitor_status_ctx = NULL;
 	}
 
@@ -993,6 +993,7 @@ static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
 	return;
 }
 
+
 /* Returns rest of string, or NULL if no match. */
 static const char *get_call(const char *p, enum ctdb_eventscript_call *call)
 {


-- 
CTDB repository


More information about the samba-cvs mailing list