50.samba : Tell winbind about every time we add/remove and ip from the node
[sahlberg/ctdb.git] / config / events.d / 50.samba
index 23dd060682a37c24dda2b0da86ee72fc386cd51b..415b89f4a6efff614e851db8e3337ae027b827d3 100755 (executable)
@@ -30,11 +30,9 @@ 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
+       /bin/mkdir -p $CTDB_VARDIR/state/samba
 
        # make sure samba is not already started
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
@@ -65,8 +63,6 @@ start_samba() {
 
        }
 
-       /usr/bin/net serverid wipe
-
        # start the winbind service
        [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
                service "$CTDB_SERVICE_WINBIND" start
@@ -76,9 +72,12 @@ start_samba() {
        # the number of smbd processes will mean that it leaves few cycles for
        # anything else
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
+               /usr/bin/net serverid wipe
+
                nice_service "$CTDB_SERVICE_NMB" start
                nice_service "$CTDB_SERVICE_SMB" start
        }
+       return 0
 }
 
 stop_samba() {
@@ -93,6 +92,8 @@ stop_samba() {
        [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
                service "$CTDB_SERVICE_WINBIND" stop
        }
+
+       return 0
 }
 
 # set default samba cleanup period - in minutes
@@ -101,13 +102,13 @@ stop_samba() {
 }
 
 # we keep a cached copy of smb.conf here
-smbconf_cache="$CTDB_BASE/state/samba/smb.conf.cache"
+smbconf_cache="$CTDB_VARDIR/state/samba/smb.conf.cache"
 
 
 #############################################
 # update the smb.conf cache in the foreground
 testparm_foreground_update() {
-    mkdir -p "$CTDB_BASE/state/samba" || exit 1
+    mkdir -p "$CTDB_VARDIR/state/samba" || exit 1
     testparm -s 2> /dev/null | egrep -v 'registry.shares.=|include.=' > "$smbconf_cache"
 }
 
@@ -203,6 +204,17 @@ periodic_cleanup() {
     smbstatus -np > /dev/null 2>&1 &
 }
 
+###########################
+
+[ "$1" = "monitor" ] && {
+ctdb_start_stop_service
+ctdb_start_stop_service "winbind"
+}
+
+is_ctdb_managed_service || is_ctdb_managed_service "winbind" || exit 0
+
+###########################
+
 case "$1" in 
      startup)
        ctdb_service_start
@@ -215,13 +227,13 @@ case "$1" in
      monitor)
        # Create a dummy file to track when we need to do periodic cleanup
        # of samba databases
-       [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
-               touch $CTDB_BASE/state/samba/periodic_cleanup
+       [ -f $CTDB_VARDIR/state/samba/periodic_cleanup ] || {
+               touch $CTDB_VARDIR/state/samba/periodic_cleanup
        }
-       [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
+       [ `/usr/bin/find $CTDB_VARDIR/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
                # Cleanup the databases
                periodic_cleanup
-               touch $CTDB_BASE/state/samba/periodic_cleanup
+               touch $CTDB_VARDIR/state/samba/periodic_cleanup
        }
 
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
@@ -258,6 +270,13 @@ case "$1" in
        }
        ;;
 
+     takeip|releaseip)
+       iface=$2
+       ip=$3
+       maskbits=$4
+
+       smbcontrol winbindd ip-dropped $ip >/dev/null 2>/dev/null
+       ;;
     *)
        ctdb_standard_event_handler "$@"
        ;;