]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
split out events for each subsystem separately
authorAndrew Tridgell <tridge@samba.org>
Fri, 1 Jun 2007 10:54:26 +0000 (20:54 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 1 Jun 2007 10:54:26 +0000 (20:54 +1000)
(This used to be ctdb commit 03c629a72f234dcc783fa1085e7edba09597c241)

ctdb/packaging/RHEL/ctdb.spec
ctdb/tests/events [new file with mode: 0755]
ctdb/tools/events
ctdb/tools/events.d/nfslock [new file with mode: 0644]
ctdb/tools/events.d/samba [new file with mode: 0644]
ctdb/tools/functions [new file with mode: 0644]
ctdb/tools/statd-callout

index 65d4756065724abb133cee1fc5db71de9732a7db..c8eaabf3d9faee523153aab9e2ef17484c7e9688 100644 (file)
@@ -58,6 +58,7 @@ mkdir -p $RPM_BUILD_ROOT%{_includedir}
 mkdir -p $RPM_BUILD_ROOT{%{_libdir},%{_includedir}}
 mkdir -p $RPM_BUILD_ROOT%{_prefix}/{bin,sbin}
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/ctdb
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/events.d
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d
 
@@ -66,6 +67,8 @@ make DESTDIR=$RPM_BUILD_ROOT install
 install -m644 setup/ctdb.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ctdb
 install -m755 setup/ctdb.init $RPM_BUILD_ROOT%{initdir}/ctdb
 install -m755 tools/events $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/events
+install -m755 tools/events.d/samba $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/events.d/samba
+install -m755 tools/events.d/nfslock $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/events.d/nfslock
 install -m755 tools/statd-callout $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/statd-callout
 install -m755 tools/onnode.ssh $RPM_BUILD_ROOT%{_bindir}
 install -m755 tools/onnode.rsh $RPM_BUILD_ROOT%{_bindir}
@@ -108,6 +111,9 @@ fi
 %attr(755,root,root) %config %{initdir}/ctdb
 
 %{_sysconfdir}/ctdb/events
+%{_sysconfdir}/ctdb/functions
+%{_sysconfdir}/ctdb/events.d/samba
+%{_sysconfdir}/ctdb/events.d/nfslock
 %{_sysconfdir}/ctdb/statd-callout
 %{_sbindir}/ctdbd
 %{_bindir}/ctdb
diff --git a/ctdb/tests/events b/ctdb/tests/events
new file mode 100755 (executable)
index 0000000..00b0e49
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+# event script for 'make test'
+
+cmd="$1"
+shift
+
+case $cmd in 
+     startup)
+       echo "`date` ctdb startup event"
+       exit 0; 
+       ;;
+       
+     takeip)
+       echo "`date` ctdb takeip event for $1 $2 $3"
+       exit 0
+       ;;
+
+     releaseip)
+       echo "`date` ctdb releaseip event for $1 $2 $3"
+       exit 0
+       ;;
+
+     recovered)
+       echo "`date` ctdb recovered event"
+       exit 0
+       ;;
+
+     shutdown)
+       echo "`date` ctdb shutdown event"
+       exit 0
+       ;;
+esac
+
+echo "`/bin/date` Invalid command $cmd"
+exit 1
index bf38bae469bc6baecc1afa10dae920c8aa50ce48..854b2ac77115379ea14fd433652783e9428b301a 100755 (executable)
@@ -1,52 +1,24 @@
 #!/bin/sh
-# sample event script for ctdb
+############################
+# main event script for ctdb
 
 . /etc/sysconfig/ctdb
+. /etc/ctdb/functions
 
 cmd="$1"
 shift
 
 case $cmd in 
+     #############################
+     # called when ctdbd starts up
      startup)
        /bin/rm -rf /etc/ctdb/state
        /bin/mkdir -p /etc/ctdb/state
-       # wait for local services to come up.
-       [ -z "$CTDB_WAIT_TCP_PORTS" ] || {
-         all_ok=0
-         echo "`/bin/date` Waiting for local tcp ports $CTDB_WAIT_TCP_PORTS"
-         while [ $all_ok -eq 0 ]; do
-                 all_ok=1
-                 for p in $CTDB_WAIT_TCP_PORTS; do
-                     /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
-                 done
-                 [ $all_ok -eq 1 ] || sleep 1
-                 /usr/bin/ctdb status > /dev/null 2>&1 || {
-                       echo "ctdb daemon has died. Exiting event startup"
-                       exit 1
-                 }
-          done
-         echo "`/bin/date` Local tcp services are up"
-       }
-       # wait for local directories to becomes available (could be slow to mount)
-       [ -z "$CTDB_WAIT_DIRECTORIES" ] || {
-         all_ok=0
-         echo "`/bin/date` Waiting for local directories $CTDB_WAIT_DIRECTORIES"
-         while [ $all_ok -eq 0 ]; do
-                 all_ok=1
-                 for d in $CTDB_WAIT_DIRECTORIES; do
-                     [ -d $d ] || all_ok=0
-                 done
-                 [ $all_ok -eq 1 ] || sleep 1
-                 /usr/bin/ctdb status > /dev/null 2>&1 || {
-                       echo "ctdb daemon has died. Exiting event startup"
-                       exit 1
-                 }
-          done
-         echo "`/bin/date` Local directories are available"
-       }
-       exit 0; 
        ;;
-       
+
+
+     ################################################
+     # called when ctdbd wants to claim an IP address
      takeip)
        if [ $# != 3 ]; then
           echo "must supply interface, IP and maskbits"
@@ -60,18 +32,14 @@ case $cmd in
                 echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface"
                 exit 1
        }
-       echo $ip >> /etc/ctdb/state/taken_ips
-       echo $ip >> /etc/ctdb/state/changed_ips
 
        # flush our route cache
        echo 1 > /proc/sys/net/ipv4/route/flush
-
-       # having a list of what IPs we have allows statd to do the right 
-       # thing via /etc/ctdb/statd-callout
-       /bin/touch /etc/ctdb/state/ip.$ip
-       exit 0
        ;;
 
+
+     ##################################################
+     # called when ctdbd wants to release an IP address
      releaseip)
        if [ $# != 3 ]; then
           echo "`/bin/date` must supply interface, IP and maskbits"
@@ -87,37 +55,35 @@ case $cmd in
 
        # flush our route cache
        echo 1 > /proc/sys/net/ipv4/route/flush
-
-       echo $ip >> /etc/ctdb/state/released_ips
-       echo $ip >> /etc/ctdb/state/changed_ips
-       /bin/rm -f /etc/ctdb/state/ip.$ip
-       exit 0
        ;;
 
+
+     ###########################################
+     # called when ctdbd has finished a recovery
      recovered)
-       # if we have taken or released any ips we must send out
-       # statd notifications to recover lost nfs locks
-       [ -x /etc/ctdb/statd-callout ] && [ -f /etc/ctdb/state/changed_ips ] && {
-               /etc/ctdb/statd-callout notify &
-       } >/dev/null 2>&1
-
-        # restart NFS to ensure that all TCP connections to the released ip
-       # are closed
-       [ -f /etc/ctdb/state/released_ips ] && {
-               ( /sbin/service nfs status > /dev/null 2>&1 && 
-                      /sbin/service nfs restart > /dev/null 2>&1 ) &
-       } > /dev/null 2>&1
-       /bin/rm -f /etc/ctdb/state/changed_ips
-       /bin/rm -f /etc/ctdb/state/released_ips
-       /bin/rm -f /etc/ctdb/state/taken_ips
-       exit 0
        ;;
 
+     ####################################
+     # called when ctdbd is shutting down
      shutdown)
-        # shutdown any services as necessary
-       exit 0
        ;;
+
+     *)
+        echo "`/bin/date` Invalid ctdb event command $cmd"
+        exit 1
+        ;;
 esac
 
-echo "`/bin/date` Invalid command $cmd"
-exit 1
+#######################################
+# call all application specific scripts
+[ -d /etc/ctdb/events.d ] && {
+    /bin/ls /etc/ctdb/events.d | /bin/grep -v '~' | 
+    while read SCRIPT; do
+       [ -x /etc/ctdb/events.d/$SCRIPT ] && {
+           /etc/ctdb/events.d/$SCRIPT $cmd "$1" "$2" "$3" || exit 1
+       }
+    done
+}
+
+# all OK
+exit 0
diff --git a/ctdb/tools/events.d/nfslock b/ctdb/tools/events.d/nfslock
new file mode 100644 (file)
index 0000000..e6700c0
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+# event strict to manage lockd and statd in a cluster environment
+
+. /etc/sysconfig/ctdb
+
+cmd="$1"
+shift
+
+case $cmd in 
+     startup)
+       /bin/mkdir -p /etc/ctdb/state/statd/ip
+       ;;
+
+     shutdown)
+       ;;
+
+     takeip)
+       ip=$2
+
+       echo $ip >> /etc/ctdb/state/statd/restart
+
+       # having a list of what IPs we have allows statd to do the right 
+       # thing via /etc/ctdb/statd-callout
+       /bin/touch /etc/ctdb/state/statd/ip/$ip
+       ;;
+
+     releaseip)
+       ip=$2
+
+       echo $ip >> /etc/ctdb/state/statd/restart
+       /bin/rm -f /etc/ctdb/state/statd/ip/$ip
+       ;;
+
+     recovered)
+       # if we have taken or released any ips we must send out
+       # statd notifications to recover lost nfs locks
+       [ -x /etc/ctdb/statd-callout ] && [ -f /etc/ctdb/state/statd/restart ] && {
+               /etc/ctdb/statd-callout notify &
+       } >/dev/null 2>&1
+
+       /bin/rm -f /etc/ctdb/state/statd/restart
+       ;;
+esac
+
+exit 0
diff --git a/ctdb/tools/events.d/samba b/ctdb/tools/events.d/samba
new file mode 100644 (file)
index 0000000..81c7d06
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+# ctdb event script for Samba
+
+PATH=/bin:/usr/bin:$PATH
+
+. /etc/sysconfig/ctdb
+
+cmd="$1"
+shift
+
+case $cmd in 
+     startup)
+       # wait for the Samba tcp ports to become available
+       smb_ports=`testparm -stv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2"`
+       ctdb_wait_tcp_ports "Samba" $smb_ports
+
+       # wait for all shared directories to become available
+       smb_dirs=`testparm -st 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
+       ctdb_wait_directories "Samba" $smb_dirs 
+       ;;
+       
+     takeip)
+       # nothing special for Samba
+       ;;
+
+     releaseip)
+       # nothing special for Samba
+       ;;
+
+     recovered)
+       # nothing special for Samba
+       exit 0
+       ;;
+
+     shutdown)
+       /etc/init.d/smb stop
+       /etc/init.d/winbind stop
+       ;;
+esac
+
+# ignore unknown commands
+exit 0
diff --git a/ctdb/tools/functions b/ctdb/tools/functions
new file mode 100644 (file)
index 0000000..df39c73
--- /dev/null
@@ -0,0 +1,54 @@
+# utility functions for ctdb event scripts
+
+
+######################################################
+# wait for a set of tcp ports
+# usage: ctdb_wait_tcp_ports SERICE_NAME <ports...>
+######################################################
+ctdb_wait_tcp_ports() {
+  service_name="$1"
+  shift
+  wait_ports="$*"
+  [ -z "$wait_ports" ] && return;
+  all_ok=0
+  echo "`/bin/date` Waiting for tcp service $service_name to start"
+  while [ $all_ok -eq 0 ]; do
+         all_ok=1
+         for p in $wait_ports; do
+             /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
+         done
+         [ $all_ok -eq 1 ] || sleep 1
+         /usr/bin/ctdb status > /dev/null 2>&1 || {
+               echo "ctdb daemon has died. Exiting tcp wait $service_name"
+               exit 1
+         }
+  done
+  echo "`/bin/date` Local tcp services for $service_name are up"
+}
+
+
+######################################################
+# wait for a set of directories
+# usage: ctdb_wait_directories SERICE_NAME <directories...>
+######################################################
+ctdb_wait_directories() {
+  service_name="$1"
+  shift
+  wait_dirs="$*"
+  [ -z "$wait_dirs" ] && return;
+  all_ok=0
+  echo "`/bin/date` 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
+         /usr/bin/ctdb status > /dev/null 2>&1 || {
+               echo "ctdb daemon has died. Exiting directory wait for $service_name"
+               exit 1
+         }
+  done
+  echo "`/bin/date` Local directories for $service_name are available"
+}
+
index d17534efb3a8bb9cc5c895dcf9c3b11ef2c84a38..92fb1aa031d54ca7a43a8d023024346be562542d 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+# this script needs to be installed so that statd points to it with the -H 
+# command line argument. The easiest way to do that is 
+
 . /etc/sysconfig/ctdb
 
 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
 
 case "$1" in
   add-client)
-        for f in `/bin/ls /etc/ctdb/state/ip.*`; do
-           fname=`/bin/basename $f`
-           ip=`echo $fname | cut -d. -f2-`
+        for f in `/bin/ls /etc/ctdb/state/statd/ip/*`; do
+           ip=`/bin/basename $f`
            [ -d $STATD_SHARED_DIRECTORY/$ip ] || /bin/mkdir $STATD_SHARED_DIRECTORY/$ip
-           /bin/touch $STATD_SHARED_DIRECTORY/$ip/$2
+           /bin/touch $STATD_SHARED_DIRECTORY/$ip/sm/$2
        done
        ;;
   del-client)
-        for f in `/bin/ls /etc/ctdb/state/ip.*`; do
-           fname=`/bin/basename $f`
-           ip=`echo $fname | cut -d. -f2-`
-           /bin/rm -f $STATD_SHARED_DIRECTORY/$ip/$2
+        for f in `/bin/ls /etc/ctdb/state/statd/ip/*`; do
+           ip=`/bin/basename $f`
+           /bin/rm -f $STATD_SHARED_DIRECTORY/$ip/sm/$2
        done
        ;;
   notify)
@@ -27,18 +28,16 @@ case "$1" in
        /sbin/service nfslock stop > /dev/null 2>&1 
        /sbin/service nfslock start > /dev/null 2>&1 
        # send out notifications to any additional ips we now serve
-        for f in `/bin/ls /etc/ctdb/state/ip.*`; do
-           fname=`/bin/basename $f`
-           ip=`echo $fname | cut -d. -f2-`
+        for f in `/bin/ls /etc/ctdb/state/statd/ip/*`; do
+           ip=`/bin/basename $f`
            [ -d $STATD_SHARED_DIRECTORY/$ip ] && {
                # we must copy to a different directory since rpc.statd gets
                # "upset" if sm-notify touches the files.
                /bin/rm -rf /tmp/statd/$ip
                /bin/mkdir -p /tmp/statd/$ip
                /bin/cp -apr $STATD_SHARED_DIRECTORY/$ip/* /tmp/statd/$ip
-               /usr/sbin/sm-notify -P /tmp/statd/$ip -v $ip -n
+               [ -x /usr/sbin/sm-notify ] && /usr/sbin/sm-notify -P /tmp/statd/$ip -v $ip -n
            }
        done
        ;;
 esac
-