we should start winbindd before we start smb
[sahlberg/ctdb.git] / config / events.d / 50.samba
1 #!/bin/sh
2 # ctdb event script for Samba
3
4 PATH=/bin:/usr/bin:$PATH
5
6 . /etc/ctdb/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 /etc/ctdb/state/samba
32
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 
36
37         # make sure samba is not already started
38         service winbind stop > /dev/null 2>&1
39         service smb stop > /dev/null 2>&1
40
41         # start Samba service. Start it reniced, as under very heavy load 
42         # the number of smbd processes will mean that it leaves few cycles for
43         # anything else
44         nice service smb start
45         service winbind start
46
47         # wait for the Samba tcp ports to become available
48         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
49         ctdb_wait_tcp_ports "Samba" $smb_ports
50
51         # wait for winbind to be ready
52         ctdb_wait_command "winbind" "wbinfo -p"
53         ;;
54         
55      takeip)
56         # nothing special for Samba
57         ;;
58
59      releaseip)
60         # nothing special for Samba
61         ;;
62
63      recovered)
64         # nothing special for Samba
65         exit 0
66         ;;
67
68      shutdown)
69         # shutdown Samba when ctdb goes down
70         service smb stop
71         service winbind stop
72         ;;
73
74      monitor)
75         # Create a dummy file to track when we need to do periodic cleanup
76         # of samba databases
77         [ -f /etc/ctdb/state/samba/periodic_cleanup ] || {
78                 touch /etc/ctdb/state/samba/periodic_cleanup
79         }
80         [ `/usr/bin/find /etc/ctdb/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
81                 # Cleanup the databases
82                 periodic_cleanup
83                 touch /etc/ctdb/state/samba/periodic_cleanup
84         }
85
86         testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
87             echo "`date` ERROR: testparm shows smb.conf is not clean"
88             exit 1
89         }
90
91         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
92         ctdb_check_directories "Samba" $smb_dirs        
93
94         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
95         ctdb_check_tcp_ports "Samba" $smb_ports
96
97         # check winbind is OK
98         ctdb_check_command "winbind" "wbinfo -p"
99         ;;
100
101 esac
102
103 # ignore unknown commands
104 exit 0