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 # function to see if ctdb manages winbind
20 check_ctdb_manages_winbind() {
21 [ -z "$CTDB_MANAGES_WINBIND" ] && {
22 secmode=`testparm -s --parameter-name=security 2> /dev/null`
25 CTDB_MANAGES_WINBIND="yes";
28 CTDB_MANAGES_WINBIND="no";
34 ###########################
35 # periodic cleanup function
37 # running smbstatus scrubs any dead entries from the connections
38 # and sessionid database
39 echo "Running periodic cleanup of samba databases"
40 smbstatus -n > /dev/null 2>&1 &
45 # create the state directory for samba
46 /bin/mkdir -p $CTDB_BASE/state/samba
48 # make sure samba is not already started
49 service smb stop > /dev/null 2>&1
50 killall -0 -q smbd && {
52 # make absolutely sure samba is dead
56 # restart the winbind service
57 check_ctdb_manages_winbind
58 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
59 service winbind stop > /dev/null 2>&1
60 killall -0 -q winbindd && {
62 # make absolutely sure winbindd is dead
63 killall -q -9 winbindd
68 # start Samba service. Start it reniced, as under very heavy load
69 # the number of smbd processes will mean that it leaves few cycles for
71 nice_service smb start
75 # nothing special for Samba
79 # nothing special for Samba
83 # nothing special for Samba
88 # shutdown Samba when ctdb goes down
91 # stop the winbind service
92 check_ctdb_manages_winbind
93 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
99 # Create a dummy file to track when we need to do periodic cleanup
101 [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
102 touch $CTDB_BASE/state/samba/periodic_cleanup
104 [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
105 # Cleanup the databases
107 touch $CTDB_BASE/state/samba/periodic_cleanup
110 testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
111 echo "ERROR: testparm shows smb.conf is not clean"
115 smb_dirs=`testparm -s 2> /dev/null | egrep '^[[:space:]]*path = ' | cut -d= -f2`
116 ctdb_check_directories "Samba" $smb_dirs
118 smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
119 ctdb_check_tcp_ports "Samba" $smb_ports
121 # check winbind is OK
122 check_ctdb_manages_winbind
123 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
124 ctdb_check_command "winbind" "wbinfo -p"
130 # ignore unknown commands