2007-06-01 14:54:26 +04:00
#!/bin/sh
# ctdb event script for Samba
PATH=/bin:/usr/bin:$PATH
2007-06-01 15:20:05 +04:00
. /etc/ctdb/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
}
###########################
# periodic cleanup function
periodic_cleanup() {
# running smbstatus scrubs any dead entries from the connections
# and sessionid database
echo "`date` Running periodic cleanup of samba databases"
smbstatus -n > /dev/null 2>&1
}
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
/bin/mkdir -p /etc/ctdb/state/samba
2007-06-03 08:39:27 +04:00
# wait for all shared directories to become available
2007-06-11 07:56:50 +04:00
smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
2007-06-03 08:39:27 +04:00
ctdb_wait_directories "Samba" $smb_dirs
2007-06-05 09:18:37 +04:00
# make sure samba is not already started
service smb stop > /dev/null 2>&1
service winbind stop > /dev/null 2>&1
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
nice service smb start
2007-06-02 12:51:05 +04:00
service winbind start
2007-06-01 14:54:26 +04:00
# wait for the Samba tcp ports to become available
2007-06-11 07:56:50 +04:00
smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
2007-06-01 14:54:26 +04:00
ctdb_wait_tcp_ports "Samba" $smb_ports
2007-06-17 05:57:42 +04:00
# wait for winbind to be ready
ctdb_wait_command "winbind" "wbinfo -p"
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
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
[ -f /etc/ctdb/state/samba/periodic_cleanup ] || {
touch /etc/ctdb/state/samba/periodic_cleanup
}
2007-06-17 21:15:08 +04:00
[ `/usr/bin/find /etc/ctdb/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-06-17 20:34:29 +04:00
touch /etc/ctdb/state/samba/periodic_cleanup
}
2007-06-11 07:56:50 +04:00
testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
2007-06-06 13:46:25 +04:00
echo "`date` ERROR: testparm shows smb.conf is not clean"
exit 1
}
2007-06-11 07:56:50 +04:00
smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
2007-06-06 06:08:42 +04:00
ctdb_check_directories "Samba" $smb_dirs
2007-06-11 07:56:50 +04:00
smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
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
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