]> git.samba.org - sahlberg/ctdb.git/blob - config/events.d/50.samba
add a mechanism to the samba event script to do periodic cleanup of the
[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 case $cmd in 
15      startup)
16         # create the state directory for samba
17         /bin/mkdir -p /etc/ctdb/state/samba
18
19         # wait for all shared directories to become available
20         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
21         ctdb_wait_directories "Samba" $smb_dirs 
22
23         # make sure samba is not already started
24         service smb stop > /dev/null 2>&1
25         service winbind stop > /dev/null 2>&1
26
27         # start Samba service. Start it reniced, as under very heavy load 
28         # the number of smbd processes will mean that it leaves few cycles for
29         # anything else
30         nice service smb start
31         service winbind start
32
33         # wait for the Samba tcp ports to become available
34         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
35         ctdb_wait_tcp_ports "Samba" $smb_ports
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         # Create a dummy file to track when we need to do periodic cleanup
59         # of samba databases
60         [ -f /etc/ctdb/state/samba/periodic_cleanup ] || {
61                 touch /etc/ctdb/state/samba/periodic_cleanup
62         }
63         [ `/usr/bin/find /etc/ctdb/state/samba/periodic_cleanup -mmin +1 | wc -l` -eq 1 ] && {
64                 # Cleanup the databases
65                 touch /etc/ctdb/state/samba/periodic_cleanup
66         }
67
68         testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
69             echo "`date` ERROR: testparm shows smb.conf is not clean"
70             exit 1
71         }
72
73         smb_dirs=`testparm -s 2> /dev/null | egrep '^\s*path = '  | cut -d= -f2`
74         ctdb_check_directories "Samba" $smb_dirs        
75
76         smb_ports=`testparm -sv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
77         ctdb_check_tcp_ports "Samba" $smb_ports
78         ;;
79
80 esac
81
82 # ignore unknown commands
83 exit 0