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
20 # autodetect use of winbind if not set in config file
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";
33 ###########################
34 # periodic cleanup function
36 # running smbstatus scrubs any dead entries from the connections
37 # and sessionid database
38 echo "`date` Running periodic cleanup of samba databases"
39 smbstatus -n > /dev/null 2>&1 &
44 # create the state directory for samba
45 /bin/mkdir -p $CTDB_BASE/state/samba
47 # make sure samba is not already started
48 service smb stop > /dev/null 2>&1
49 killall -0 -q smbd && {
51 # make absolutely sure samba is dead
55 # restart the winbind service
56 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
57 service winbind stop > /dev/null 2>&1
58 killall -0 -q winbindd && {
60 # make absolutely sure winbindd is dead
61 killall -q -9 winbindd
66 # start Samba service. Start it reniced, as under very heavy load
67 # the number of smbd processes will mean that it leaves few cycles for
69 nice service smb start
73 # nothing special for Samba
77 # nothing special for Samba
81 # nothing special for Samba
86 # shutdown Samba when ctdb goes down
89 # stop the winbind service
90 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
96 # Create a dummy file to track when we need to do periodic cleanup
98 [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
99 touch $CTDB_BASE/state/samba/periodic_cleanup
101 [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
102 # Cleanup the databases
104 touch $CTDB_BASE/state/samba/periodic_cleanup
107 testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
108 echo "`date` ERROR: testparm shows smb.conf is not clean"
112 smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = ' | cut -d= -f2`
113 ctdb_check_directories "Samba" $smb_dirs
115 smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
116 ctdb_check_tcp_ports "Samba" $smb_ports
118 # check winbind is OK
119 [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
120 ctdb_check_command "winbind" "wbinfo -p"
126 # ignore unknown commands