Now vaguely tested initscript updates.
authorMartin Schwenke <martin@meltin.net>
Thu, 19 Nov 2009 05:48:19 +0000 (16:48 +1100)
committerMartin Schwenke <martin@meltin.net>
Thu, 19 Nov 2009 05:48:19 +0000 (16:48 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit f1e350f9edb74cc44b6c5be4c062fd93e98ba8c4)

ctdb/config/ctdb.init
ctdb/config/events.d/01.reclock
ctdb/config/events.d/20.multipathd
ctdb/config/events.d/40.vsftpd
ctdb/config/events.d/41.httpd
ctdb/config/events.d/50.samba
ctdb/config/events.d/70.iscsi
ctdb/config/events.d/99.timeout
ctdb/config/functions

index 67747fd149da73f95a2d84d146b5fa4d1249cbdf..4bd570d343acf400db73dc65ae47d88fa8cb0896 100755 (executable)
@@ -250,7 +250,7 @@ status() {
 }
 
 
-case "$1" in
+case "$cmd" in
     start)
        start
        ;;
index 3d335507ddde76164001d8dc3b87b1c3b0dc73fa..1b6cbf09e440a2aa5eaada9f869bd2ddaaf70335 100755 (executable)
@@ -10,15 +10,16 @@ case $cmd in
        ;;
     
     monitor)
+       RECLOCKFILE=$(ctdb -Y getreclock)
+
        ctdb_counter_incr
-       (ctdb_counter_limit 200 >/dev/null 2>&1) || {
-           echo "Reclock file \"$RECLOCKFILE\" can not be accessed. Shutting down."
+       (ctdb_check_counter_limit 200 >/dev/null 2>&1) || {
+           echo "Reclock file $RECLOCKFILE\" can not be accessed. Shutting down."
            df
            sleep 1
            ctdb shutdown
        }
 
-       RECLOCKFILE=$(ctdb -Y getreclock)
        [ -z "$RECLOCKFILE" ] && {
            # we are not using a reclock file
            ctdb_counter_init
@@ -34,8 +35,7 @@ case $cmd in
            }
        ) >/dev/null 2>/dev/null &
 
-
-       ctdb_counter_limit 3
+       ctdb_check_counter_limit 3 quiet
        ;;
     status)
        ctdb_checkstatus || exit $?
index 24f8f7aa9849ae10e420dc0de39c83e159c7fba2..cf722d8ce985851891a9d9f299815b71df8faf24 100644 (file)
@@ -6,9 +6,10 @@
 #   CTDB_MONITOR_MPDEVICES="device1 device2 ..."
 #
 
+. $CTDB_BASE/functions
+
 service_name="multipathd"
 
-. $CTDB_BASE/functions
 loadconfig 
 
 [ -z "$CTDB_MONITOR_MPDEVICES" ] && {
index d231690a2350b4b32a9910c0212c83d436995b71..582604aae36417c6267581c994d762bbc9dd3c82 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 # event strict to manage vsftpd in a cluster environment
 
+. $CTDB_BASE/functions
+
 service_name="vsftpd"
 # make sure the service is stopped first
 service_start="service $service_name stop > /dev/null 2>&1 ; service $service_name start"
@@ -9,8 +11,6 @@ service_reconfigure="service $service_name restart"
 service_fail_limit=2
 service_tcp_ports=21
 
-. $CTDB_BASE/functions
-
 loadconfig
 
 ctdb_start_stop_service
index 3e43f0f2127c26e10ee74a2827a9452a0cf88a09..7f9ee23f2476fb27fec9788f51a5e4d7758bd451 100755 (executable)
@@ -28,7 +28,7 @@ cleanup_httpd_semaphore_leak() {
 ##########
 
 service_start="cleanup_httpd_semaphore_leak; service $service_name start"
-service_stop="service $service_name stop; killall -q -9 $service_name"
+service_stop="service $service_name stop; killall -q -9 $service_name || true"
 service_reconfigure="service $service_name restart"
 
 loadconfig
index bd4c5ff0063f920aedd88aec44eb704d13be3842..e285347f604d149f3a7c1b91415a3dbfe259916e 100755 (executable)
@@ -1,13 +1,7 @@
 #!/bin/sh
 # ctdb event script for Samba
 
-PATH=/bin:/usr/bin:$PATH
-
-service_name="samba"
-
 . $CTDB_BASE/functions
-loadconfig ctdb
-loadconfig samba
 
 detect_init_style
 
@@ -22,11 +16,6 @@ case $CTDB_INIT_STYLE in
                CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
                CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
                ;;
-       redhat)
-               CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
-               CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
-               CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
-               ;;
        *)
                # should not happen, but for now use redhat style as default:
                CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
@@ -35,11 +24,69 @@ case $CTDB_INIT_STYLE in
                ;;
 esac
 
-cmd="$1"
-shift
+service_name="samba"
+service_start="start_samba"
+service_stop="stop_samba"
+
+loadconfig
 
 [ "$CTDB_MANAGES_SAMBA" = "yes" ] || [ "$CTDB_MANAGES_WINBIND" = "yes" ] || exit 0
 
+start_samba() {
+       # create the state directory for samba
+       /bin/mkdir -p $CTDB_BASE/state/samba
+
+       # make sure samba is not already started
+       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
+               service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
+               service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
+               killall -0 -q smbd && {
+                   sleep 1
+                   # make absolutely sure samba is dead
+                   killall -q -9 smbd
+               }
+
+               killall -0 -q nmbd && {
+                   sleep 1
+                   # make absolutely sure samba is dead
+                   killall -q -9 nmbd
+               }
+       }
+
+       # restart the winbind service
+       check_ctdb_manages_winbind
+       [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
+               service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
+               killall -0 -q winbindd && {
+                   sleep 1
+                   # make absolutely sure winbindd is dead
+                   killall -q -9 winbindd
+               }
+               service "$CTDB_SERVICE_WINBIND" start
+       }
+
+       # start Samba service. Start it reniced, as under very heavy load 
+       # the number of smbd processes will mean that it leaves few cycles for
+       # anything else
+       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
+               nice_service "$CTDB_SERVICE_NMB" start
+               nice_service "$CTDB_SERVICE_SMB" start
+       }
+}
+
+stop_samba() {
+       # shutdown Samba when ctdb goes down
+       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
+               service "$CTDB_SERVICE_SMB" stop
+               service "$CTDB_SERVICE_NMB" stop
+       }
+
+       # stop the winbind service
+       check_ctdb_manages_winbind
+       [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
+               service "$CTDB_SERVICE_WINBIND" stop
+       }
+}
 
 # set default samba cleanup period - in minutes
 [ -z "$SAMBA_CLEANUP_PERIOD" ] && {
@@ -143,72 +190,11 @@ periodic_cleanup() {
 
 case $cmd in 
      startup)
-       # create the state directory for samba
-       /bin/mkdir -p $CTDB_BASE/state/samba
-
-       # make sure samba is not already started
-       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
-               service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
-               service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
-               killall -0 -q smbd && {
-                   sleep 1
-                   # make absolutely sure samba is dead
-                   killall -q -9 smbd
-               }
-
-               killall -0 -q nmbd && {
-                   sleep 1
-                   # make absolutely sure samba is dead
-                   killall -q -9 nmbd
-               }
-       }
-
-       # restart the winbind service
-       check_ctdb_manages_winbind
-       [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
-               service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
-               killall -0 -q winbindd && {
-                   sleep 1
-                   # make absolutely sure winbindd is dead
-                   killall -q -9 winbindd
-               }
-               service "$CTDB_SERVICE_WINBIND" start
-       }
-
-       # start Samba service. Start it reniced, as under very heavy load 
-       # the number of smbd processes will mean that it leaves few cycles for
-       # anything else
-       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
-               nice_service "$CTDB_SERVICE_NMB" start
-               nice_service "$CTDB_SERVICE_SMB" start
-       }
+       ctdb_service_start
        ;;
        
-     takeip)
-       # nothing special for Samba
-       ;;
-
-     releaseip)
-       # nothing special for Samba
-       ;;
-
-     recovered)
-       # nothing special for Samba
-       exit 0
-       ;;
-
      shutdown)
-       # shutdown Samba when ctdb goes down
-       [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
-               service "$CTDB_SERVICE_SMB" stop
-               service "$CTDB_SERVICE_NMB" stop
-       }
-
-       # stop the winbind service
-       check_ctdb_manages_winbind
-       [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
-               service "$CTDB_SERVICE_WINBIND" stop
-       }
+       ctdb_service_stop
        ;;
 
      monitor)
@@ -257,6 +243,9 @@ case $cmd in
        }
        ;;
 
+    status)
+       ctdb_checkstatus || exit $?
+       ;;
 esac
 
 # ignore unknown commands
index 2ab34aca3fa51eb6001bd13d18f1c236ca9e5de1..8cbf457eb4eb446420e9c5ed8c5e31a28561e8b3 100755 (executable)
@@ -1,10 +1,10 @@
 #!/bin/sh
 # ctdb event script for TGTD based iSCSI
 
-service_name="iscsi"
-
 . $CTDB_BASE/functions
 
+service_name="iscsi"
+
 ctdb_start_stop_service
 
 [ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
index 6a5aed05a38a1599619b4e8c9e2e58d3c938e1af..a1201bfc5c20172c3bfe2649cef1d484a12abf41 100755 (executable)
@@ -7,7 +7,7 @@
 . $CTDB_BASE/functions
 loadconfig ctdb
 
-[ "x$CTDB_RUN_TIMEOUT_MONITOR" = "xyes" ] || exit 0
+[ "$CTDB_RUN_TIMEOUT_MONITOR" = "yes" ] || exit 0
 
 case $cmd in
     monitor)
index d68f6073765f35d292421b0495d740fa080f46a6..2d60cb4309759262b88b76ded7bafb384397baf8 100644 (file)
@@ -509,7 +509,7 @@ _ctdb_counter_common () {
 ctdb_counter_init () {
     _ctdb_counter_common
 
-    echo -n > "$_counter_file"
+    >"$_counter_file"
 }
 ctdb_counter_incr () {
     _ctdb_counter_common
@@ -520,13 +520,16 @@ ctdb_counter_incr () {
 ctdb_check_counter_limit () {
     _ctdb_counter_common
 
+    _limit="${1:-${service_fail_limit}}"
+    _quiet="$2"
+
     # unary counting!
     _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
-    if [ $_size -ge $service_fail_limit ] ; then
-       echo "ERROR: more than $service_fail_limit consecutive failures, marking cluster unhealthy"
+    if [ $_size -ge $_limit ] ; then
+       echo "ERROR: more than $_limit consecutive failures for $service_name, marking cluster unhealthy"
        exit 1
-    else
-       echo "WARNING: less than $service_fail_limit consecutive failures, not unhealthy yet"
+    elif [ $_size -gt 0 -a -z "$_quiet" ] ; then
+       echo "WARNING: less than $_limit consecutive failures ($_size) for $service_name, not unhealthy yet"
     fi
 }
 ########################################################
@@ -585,7 +588,7 @@ ctdb_service_unset_reconfigure ()
 ctdb_service_reconfigure ()
 {
     if [ -n "$service_reconfigure" ] ; then
-       $service_reconfigure
+       eval $service_reconfigure
     else
        service "$service_name" restart
     fi
@@ -641,7 +644,7 @@ ctdb_start_stop_service ()
 ctdb_service_start ()
 {
     if [ -n "$service_start" ] ; then
-       $service_start
+       eval $service_start
     else
        service "$service_name" start
     fi
@@ -651,7 +654,7 @@ ctdb_service_start ()
 ctdb_service_stop ()
 {
     if [ -n "$service_stop" ] ; then
-       $service_stop
+       eval $service_stop
     else
        service "$service_name" stop
     fi
@@ -673,6 +676,7 @@ ctdb_service_stop ()
 
 # A reasonable default is the basename of the eventscript.
 service_name="${0##*/}" # basename
+service_fail_limit=1
 
 ctdb_event="$1" ; shift
 cmd="$ctdb_event"