2007-06-01 14:54:26 +04:00
#!/bin/sh
# ctdb event script for Samba
PATH=/bin:/usr/bin:$PATH
2007-09-14 08:14:03 +04:00
. $CTDB_BASE/functions
2007-06-03 16:07:07 +04:00
loadconfig ctdb
2007-06-01 14:54:26 +04:00
cmd="$1"
shift
2007-06-02 12:51:05 +04:00
[ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
2007-06-17 21:15:08 +04:00
# set default samba cleanup period - in minutes
[ -z "$SAMBA_CLEANUP_PERIOD" ] && {
SAMBA_CLEANUP_PERIOD=10
}
2007-11-18 07:14:54 +03:00
# autodetect use of winbind if not set in config file
[ -z "$CTDB_MANAGES_WINBIND" ] && {
secmode=`testparm -s --parameter-name=security 2> /dev/null`
case $secmode in
ADS|DOMAIN)
CTDB_MANAGES_WINBIND="yes";
;;
*)
CTDB_MANAGES_WINBIND="no";
;;
esac
}
2007-06-17 21:15:08 +04:00
###########################
# periodic cleanup function
periodic_cleanup() {
# running smbstatus scrubs any dead entries from the connections
# and sessionid database
2008-01-16 14:06:44 +03:00
echo "Running periodic cleanup of samba databases"
2008-01-07 15:41:07 +03:00
smbstatus -n > /dev/null 2>&1 &
2007-06-17 21:15:08 +04:00
}
2007-06-01 14:54:26 +04:00
case $cmd in
startup)
2007-06-17 20:34:29 +04:00
# create the state directory for samba
2007-09-14 08:14:03 +04:00
/bin/mkdir -p $CTDB_BASE/state/samba
2007-06-17 20:34:29 +04:00
2007-06-05 09:18:37 +04:00
# make sure samba is not already started
2007-08-16 05:18:16 +04:00
service smb stop > /dev/null 2>&1
2008-01-07 06:31:13 +03:00
killall -0 -q smbd && {
sleep 1
# make absolutely sure samba is dead
killall -q -9 smbd
}
2007-11-14 08:17:52 +03:00
# restart the winbind service
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
service winbind stop > /dev/null 2>&1
2008-01-07 06:31:13 +03:00
killall -0 -q winbindd && {
2007-11-14 08:17:52 +03:00
sleep 1
2008-01-07 06:31:13 +03:00
# make absolutely sure winbindd is dead
killall -q -9 winbindd
2007-11-14 08:17:52 +03:00
}
service winbind start
2007-09-13 08:36:23 +04:00
}
2007-06-05 09:18:37 +04:00
2007-06-05 11:43:19 +04:00
# 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
2008-02-13 00:20:20 +03:00
nice_service smb start
2007-06-01 14:54:26 +04:00
;;
takeip)
# nothing special for Samba
;;
releaseip)
# nothing special for Samba
;;
recovered)
# nothing special for Samba
exit 0
;;
shutdown)
2007-06-01 18:10:22 +04:00
# shutdown Samba when ctdb goes down
2007-06-02 12:51:05 +04:00
service smb stop
2007-11-14 08:17:52 +03:00
# stop the winbind service
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
service winbind stop
}
2007-06-01 14:54:26 +04:00
;;
2007-06-06 06:08:42 +04:00
monitor)
2007-06-17 20:34:29 +04:00
# Create a dummy file to track when we need to do periodic cleanup
# of samba databases
2007-09-14 08:14:03 +04:00
[ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
touch $CTDB_BASE/state/samba/periodic_cleanup
2007-06-17 20:34:29 +04:00
}
2007-09-14 08:14:03 +04:00
[ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
2007-06-17 20:34:29 +04:00
# Cleanup the databases
2007-06-17 21:15:08 +04:00
periodic_cleanup
2007-09-14 08:14:03 +04:00
touch $CTDB_BASE/state/samba/periodic_cleanup
2007-06-17 20:34:29 +04:00
}
2007-06-11 07:56:50 +04:00
testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
2008-01-16 14:06:44 +03:00
echo "ERROR: testparm shows smb.conf is not clean"
2007-06-06 13:46:25 +04:00
exit 1
}
2008-01-28 09:27:16 +03:00
smb_dirs=`testparm -s 2> /dev/null | egrep '^[[:space:]]*path = ' | cut -d= -f2`
2007-06-06 06:08:42 +04:00
ctdb_check_directories "Samba" $smb_dirs
2007-09-14 03:24:34 +04:00
smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
2007-06-06 06:08:42 +04:00
ctdb_check_tcp_ports "Samba" $smb_ports
2007-06-17 06:05:29 +04:00
# check winbind is OK
2007-11-14 08:17:52 +03:00
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
ctdb_check_command "winbind" "wbinfo -p"
}
2007-06-06 06:08:42 +04:00
;;
2007-06-01 14:54:26 +04:00
esac
# ignore unknown commands
exit 0