2 # ctdb event script for Samba
4 PATH=/bin:/usr/bin:$PATH
13 [ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
15 # set default samba cleanup period - in minutes
16 [ -z "$SAMBA_CLEANUP_PERIOD" ] && {
17 SAMBA_CLEANUP_PERIOD=10
20 # function to see if ctdb manages winbind
21 check_ctdb_manages_winbind() {
22 [ -z "$CTDB_MANAGES_WINBIND" ] && {
23 secmode=`testparm -s --parameter-name=security 2> /dev/null`
26 CTDB_MANAGES_WINBIND="yes";
29 CTDB_MANAGES_WINBIND="no";
35 ###########################
36 # periodic cleanup function
38 # running smbstatus scrubs any dead entries from the connections
39 # and sessionid database
40 echo "Running periodic cleanup of samba databases"
41 smbstatus -n > /dev/null 2>&1 &
46 # create the state directory for samba
47 /bin/mkdir -p $CTDB_BASE/state/samba
49 # make sure samba is not already started
50 service smb stop > /dev/null 2>&1
51 killall -0 -q smbd && {
53 # make absolutely sure samba is dead
57 # restart the winbind service
58 check_ctdb_manages_winbind
59 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
60 service winbind stop > /dev/null 2>&1
61 killall -0 -q winbindd && {
63 # make absolutely sure winbindd is dead
64 killall -q -9 winbindd
69 # start Samba service. Start it reniced, as under very heavy load
70 # the number of smbd processes will mean that it leaves few cycles for
72 nice_service smb start
76 # nothing special for Samba
80 # nothing special for Samba
84 # nothing special for Samba
89 # shutdown Samba when ctdb goes down
92 # stop the winbind service
93 check_ctdb_manages_winbind
94 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
100 # Create a dummy file to track when we need to do periodic cleanup
102 [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
103 touch $CTDB_BASE/state/samba/periodic_cleanup
105 [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
106 # Cleanup the databases
108 touch $CTDB_BASE/state/samba/periodic_cleanup
111 testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
112 echo "ERROR: testparm shows smb.conf is not clean"
116 [ "$CTDB_SAMBA_SKIP_SHARE_CHECK" != "yes" ] && {
118 smb_dirs=`testparm -s 2> /dev/null | egrep '^[[:space:]]*path = ' | cut -d= -f2`
119 ctdb_check_directories "Samba" $smb_dirs
122 smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
123 ctdb_check_tcp_ports "Samba" $smb_ports
125 # check winbind is OK
126 check_ctdb_manages_winbind
127 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
128 ctdb_check_command "winbind" "wbinfo -p"
134 # ignore unknown commands