2 # ctdb event script for Samba
4 PATH=/bin:/usr/bin:$PATH
12 [ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
14 # set default samba cleanup period - in minutes
15 [ -z "$SAMBA_CLEANUP_PERIOD" ] && {
16 SAMBA_CLEANUP_PERIOD=10
19 ###########################
20 # periodic cleanup function
22 # running smbstatus scrubs any dead entries from the connections
23 # and sessionid database
24 echo "`date` Running periodic cleanup of samba databases"
25 smbstatus -n > /dev/null 2>&1
30 # create the state directory for samba
31 /bin/mkdir -p /etc/ctdb/state/samba
33 # wait for all shared directories to become available
34 smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
35 ctdb_wait_directories "Samba" $smb_dirs
37 # make sure samba is not already started
38 service smb stop > /dev/null 2>&1
39 service winbind stop > /dev/null 2>&1
41 # start Samba service. Start it reniced, as under very heavy load
42 # the number of smbd processes will mean that it leaves few cycles for
45 nice service smb start
47 # wait for the Samba tcp ports to become available
48 smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
49 ctdb_wait_tcp_ports "Samba" $smb_ports
51 # wait for winbind to be ready
52 ctdb_wait_command "winbind" "wbinfo -p"
56 # nothing special for Samba
60 # nothing special for Samba
64 # nothing special for Samba
69 # shutdown Samba when ctdb goes down
75 # Create a dummy file to track when we need to do periodic cleanup
77 [ -f /etc/ctdb/state/samba/periodic_cleanup ] || {
78 touch /etc/ctdb/state/samba/periodic_cleanup
80 [ `/usr/bin/find /etc/ctdb/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
81 # Cleanup the databases
83 touch /etc/ctdb/state/samba/periodic_cleanup
86 testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
87 echo "`date` ERROR: testparm shows smb.conf is not clean"
91 smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
92 ctdb_check_directories "Samba" $smb_dirs
94 smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
95 ctdb_check_tcp_ports "Samba" $smb_ports
98 ctdb_check_command "winbind" "wbinfo -p"
103 # ignore unknown commands