- merged ctdb_store test from ronnie
[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 . /etc/ctdb/functions
7 loadconfig ctdb
8
9 cmd="$1"
10 shift
11
12 [ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
13
14 case $cmd in 
15      startup)
16         # wait for all shared directories to become available
17         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
18         ctdb_wait_directories "Samba" $smb_dirs 
19
20         # make sure samba is not already started
21         service smb stop > /dev/null 2>&1
22         service winbind stop > /dev/null 2>&1
23
24         # start Samba service. Start it reniced, as under very heavy load 
25         # the number of smbd processes will mean that it leaves few cycles for
26         # anything else
27         nice service smb start
28         service winbind start
29
30         # wait for the Samba tcp ports to become available
31         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
32         ctdb_wait_tcp_ports "Samba" $smb_ports
33
34         # wait for winbind to be ready
35         ctdb_wait_command "winbind" "wbinfo -p"
36         ;;
37         
38      takeip)
39         # nothing special for Samba
40         ;;
41
42      releaseip)
43         # nothing special for Samba
44         ;;
45
46      recovered)
47         # nothing special for Samba
48         exit 0
49         ;;
50
51      shutdown)
52         # shutdown Samba when ctdb goes down
53         service smb stop
54         service winbind stop
55         ;;
56
57      monitor)
58         testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
59             echo "`date` ERROR: testparm shows smb.conf is not clean"
60             exit 1
61         }
62
63         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
64         ctdb_check_directories "Samba" $smb_dirs        
65
66         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
67         ctdb_check_tcp_ports "Samba" $smb_ports
68
69         # check winbind is OK
70         ctdb_check_command "winbind" "wbinfo -p"
71         ;;
72
73 esac
74
75 # ignore unknown commands
76 exit 0