add CTDB_MANAGES_WINBIND to /etc/sysconfig/ctdb to allow ctdb to be used
[metze/ctdb/wip.git] / config / events.d / 50.samba
1 #!/bin/sh
2 # ctdb event script for Samba
3
4 PATH=/bin:/usr/bin:$PATH
5
6 . $CTDB_BASE/functions
7 loadconfig ctdb
8
9 cmd="$1"
10 shift
11
12 [ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
13
14 # set default samba cleanup period - in minutes
15 [ -z "$SAMBA_CLEANUP_PERIOD" ] && {
16     SAMBA_CLEANUP_PERIOD=10
17 }
18
19 ###########################
20 # periodic cleanup function
21 periodic_cleanup() {
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
26 }
27
28 case $cmd in 
29      startup)
30         # create the state directory for samba
31         /bin/mkdir -p $CTDB_BASE/state/samba
32
33         # make sure samba is not already started
34         service smb stop > /dev/null 2>&1
35
36         # restart the winbind service
37         [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
38                 service winbind stop > /dev/null 2>&1
39                 killall -0 -q smbd winbindd && {
40                     sleep 1
41                     # make absolutely sure samba is dead
42                     killall -q -9 smbd winbindd
43                 }
44                 service winbind start
45         }
46
47         # start Samba service. Start it reniced, as under very heavy load 
48         # the number of smbd processes will mean that it leaves few cycles for
49         # anything else
50         nice service smb start
51         ;;
52         
53      takeip)
54         # nothing special for Samba
55         ;;
56
57      releaseip)
58         # nothing special for Samba
59         ;;
60
61      recovered)
62         # nothing special for Samba
63         exit 0
64         ;;
65
66      shutdown)
67         # shutdown Samba when ctdb goes down
68         service smb stop
69
70         # stop the winbind service
71         [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
72                 service winbind stop
73         }
74         ;;
75
76      monitor)
77         # Create a dummy file to track when we need to do periodic cleanup
78         # of samba databases
79         [ -f $CTDB_BASE/state/samba/periodic_cleanup ] || {
80                 touch $CTDB_BASE/state/samba/periodic_cleanup
81         }
82         [ `/usr/bin/find $CTDB_BASE/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
83                 # Cleanup the databases
84                 periodic_cleanup
85                 touch $CTDB_BASE/state/samba/periodic_cleanup
86         }
87
88         testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
89             echo "`date` ERROR: testparm shows smb.conf is not clean"
90             exit 1
91         }
92
93         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
94         ctdb_check_directories "Samba" $smb_dirs        
95
96         smb_ports=`testparm -s --parameter-name="smb ports" 2> /dev/null`
97         ctdb_check_tcp_ports "Samba" $smb_ports
98
99         # check winbind is OK
100         [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
101                 ctdb_check_command "winbind" "wbinfo -p"
102         }
103         ;;
104
105 esac
106
107 # ignore unknown commands
108 exit 0