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
Andrew Tridgell 6b50533c22 fixed egrep pattern to use more compatible expression for spaces
(This used to be ctdb commit 2da3871417bb05da8802093ceeb02e89102d99ad)
2008-01-28 17:27:16 +11:00

128 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# ctdb event script for Samba
PATH=/bin:/usr/bin:$PATH
. $CTDB_BASE/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
}
# 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
}
###########################
# periodic cleanup function
periodic_cleanup() {
# running smbstatus scrubs any dead entries from the connections
# and sessionid database
echo "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 $CTDB_BASE/state/samba
# make sure samba is not already started
service smb stop > /dev/null 2>&1
killall -0 -q smbd && {
sleep 1
# make absolutely sure samba is dead
killall -q -9 smbd
}
# restart the winbind service
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
service winbind stop > /dev/null 2>&1
killall -0 -q winbindd && {
sleep 1
# make absolutely sure winbindd is dead
killall -q -9 winbindd
}
service winbind start
}
# 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
;;
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
# stop the winbind service
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
service winbind stop
}
;;
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
}
[ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
# Cleanup the databases
periodic_cleanup
touch $CTDB_BASE/state/samba/periodic_cleanup
}
testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
echo "ERROR: testparm shows smb.conf is not clean"
exit 1
}
smb_dirs=`testparm -s 2> /dev/null | egrep '^[[:space:]]*path = ' | cut -d= -f2`
ctdb_check_directories "Samba" $smb_dirs
smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
ctdb_check_tcp_ports "Samba" $smb_ports
# check winbind is OK
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
ctdb_check_command "winbind" "wbinfo -p"
}
;;
esac
# ignore unknown commands
exit 0