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 $CTDB_BASE/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
40 killall -0 -q smbd winbindd && {
42 # make absolutely sure samba is dead
43 killall -q -9 smbd winbindd
46 # start Samba service. Start it reniced, as under very heavy load
47 # the number of smbd processes will mean that it leaves few cycles for
50 nice service smb start
52 # wait for the Samba tcp ports to become available
53 smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
54 ctdb_wait_tcp_ports "Samba" $smb_ports
56 # wait for winbind to be ready
57 ctdb_wait_command "winbind" "wbinfo -p"
61 # nothing special for Samba
65 # nothing special for Samba
69 # nothing special for Samba
74 # shutdown Samba when ctdb goes down
80 # Create a dummy file to track when we need to do periodic cleanup
82 [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
83 touch $CTDB_BASE/state/samba/periodic_cleanup
85 [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
86 # Cleanup the databases
88 touch $CTDB_BASE/state/samba/periodic_cleanup
91 testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
92 echo "`date` ERROR: testparm shows smb.conf is not clean"
96 smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
97 ctdb_check_directories "Samba" $smb_dirs
99 smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
100 ctdb_check_tcp_ports "Samba" $smb_ports
102 # check winbind is OK
103 ctdb_check_command "winbind" "wbinfo -p"
108 # ignore unknown commands