the event scripts no longer need to show a date, as its done by the main ctdbd loggin...
[metze/ctdb/wip.git] / config / events.d / 00.ctdb
1 #!/bin/sh
2 ############################
3 # main event script for ctdb
4 #
5 # This script is called with one of the following sets of arguments
6 #     startup    : called when ctdb starts
7 #     shutdown   : called when ctdb shuts down
8 #     takeip     : called when an IP address is taken over
9 #     releaseip  : called when an IP address is released
10 #     recovered  : called when ctdb has finished a recovery event
11
12 . $CTDB_BASE/functions
13 loadconfig ctdb
14
15 # ensure we have /bin and /usr/bin in the path
16 PATH=/bin:/usr/bin:$PATH
17
18 cmd="$1"
19 shift
20
21 # set default samba cleanup period - in minutes
22 [ -z "$CTDB_VACUUM_PERIOD" ] && {
23     CTDB_VACUUM_PERIOD=5
24 }
25
26 ###########################
27 # periodic vacuum function
28 periodic_vacuum() {
29     # this cleans up dead records and repacks the databases
30     ( time ctdb vacuum 200000 -T 30; time ctdb repack -T 30 ) > $CTDB_BASE/state/vacuum.log 2>&1 &
31 }
32
33 case $cmd in 
34      startup)
35         # make sure we have a blank state directory for the scripts to work with
36         /bin/rm -rf $CTDB_BASE/state
37         /bin/mkdir -p $CTDB_BASE/state
38
39         # set any tunables from the config file
40         set | grep ^CTDB_SET_ | cut -d_ -f3- | 
41         while read v; do
42             varname=`echo $v | cut -d= -f1`
43             value=`echo $v | cut -d= -f2`
44             ctdb setvar $varname $value || exit 1
45             echo "Set $varname to $value"
46         done || exit 1
47         ;;
48
49     monitor)
50         # Create a dummy file to track when we need to do periodic cleanup
51         # of samba databases
52         [ -f $CTDB_BASE/state/periodic_vacuum ] || {
53                 touch $CTDB_BASE/state/periodic_vacuum
54         }
55         [ `/usr/bin/find $CTDB_BASE/state/periodic_vacuum -mmin +$CTDB_VACUUM_PERIOD | wc -l` -eq 1 ] && {
56                 # vacuum the databases
57                 touch $CTDB_BASE/state/periodic_vacuum
58                 periodic_vacuum
59         }
60         
61 esac
62
63 # all OK
64 exit 0