1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
samba-mirror/ctdb/config/events.d/50.samba

110 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# ctdb event script for Samba
PATH=/bin:/usr/bin:$PATH
. /etc/ctdb/functions
loadconfig ctdb
cmd="$1"
shift
[ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
# 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
}
case $cmd in
startup)
# create the state directory for samba
/bin/mkdir -p /etc/ctdb/state/samba
# wait for all shared directories to become available
smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
ctdb_wait_directories "Samba" $smb_dirs
# make sure samba is not already started
service smb stop > /dev/null 2>&1
service winbind stop > /dev/null 2>&1
killall -0 -q smbd winbindd && {
sleep 1
# make absolutely sure samba is dead
killall -q -9 smbd winbindd
}
# 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
service winbind start
nice service smb start
# wait for the Samba tcp ports to become available
smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
ctdb_wait_tcp_ports "Samba" $smb_ports
# wait for winbind to be ready
ctdb_wait_command "winbind" "wbinfo -p"
;;
takeip)
# nothing special for Samba
;;
releaseip)
# nothing special for Samba
;;
recovered)
# nothing special for Samba
exit 0
;;
shutdown)
# shutdown Samba when ctdb goes down
service smb stop
service winbind stop
;;
monitor)
# 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
}
[ `/usr/bin/find /etc/ctdb/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
# Cleanup the databases
periodic_cleanup
touch /etc/ctdb/state/samba/periodic_cleanup
}
testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
echo "`date` ERROR: testparm shows smb.conf is not clean"
exit 1
}
smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
ctdb_check_directories "Samba" $smb_dirs
smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
ctdb_check_tcp_ports "Samba" $smb_ports
# check winbind is OK
ctdb_check_command "winbind" "wbinfo -p"
;;
esac
# ignore unknown commands
exit 0