2007-05-29 07:01:31 +04:00
#!/bin/sh
2007-06-01 14:54:26 +04:00
############################
# main event script for ctdb
2007-06-04 09:09:03 +04:00
#
# This script is called with one of the following sets of arguments
# startup : called when ctdb starts
# shutdown : called when ctdb shuts down
2007-06-04 17:54:46 +04:00
# takeip : called when an IP address is taken over
# releaseip : called when an IP address is released
# recovered : called when ctdb has finished a recovery event
2007-05-29 07:01:31 +04:00
2007-09-14 08:14:03 +04:00
. $CTDB_BASE/functions
2007-06-03 16:07:07 +04:00
loadconfig ctdb
2007-05-30 06:27:58 +04:00
2007-06-04 09:09:03 +04:00
# ensure we have /bin and /usr/bin in the path
PATH=/bin:/usr/bin:$PATH
2007-05-29 07:01:31 +04:00
cmd="$1"
shift
2008-01-10 02:04:03 +03:00
# set default samba cleanup period - in minutes
[ -z "$CTDB_VACUUM_PERIOD" ] && {
CTDB_VACUUM_PERIOD=5
}
###########################
# periodic vacuum function
periodic_vacuum() {
# this cleans up dead records and repacks the databases
( time ctdb vacuum 200000 -T 30; time ctdb repack -T 30 ) > $CTDB_BASE/state/vacuum.log 2>&1 &
}
2007-05-29 07:01:31 +04:00
case $cmd in
2007-05-30 06:27:58 +04:00
startup)
2007-06-04 09:09:03 +04:00
# make sure we have a blank state directory for the scripts to work with
2007-09-14 08:14:03 +04:00
/bin/rm -rf $CTDB_BASE/state
/bin/mkdir -p $CTDB_BASE/state
2007-06-04 14:05:31 +04:00
# set any tunables from the config file
set | grep ^CTDB_SET_ | cut -d_ -f3- |
while read v; do
varname=`echo $v | cut -d= -f1`
value=`echo $v | cut -d= -f2`
ctdb setvar $varname $value || exit 1
echo "`date` Set $varname to $value"
2007-10-29 04:34:45 +03:00
done || exit 1
2007-05-30 06:27:58 +04:00
;;
2008-01-10 02:04:03 +03:00
monitor)
# Create a dummy file to track when we need to do periodic cleanup
# of samba databases
[ -f $CTDB_BASE/state/periodic_vacuum ] || {
touch $CTDB_BASE/state/periodic_vacuum
}
[ `/usr/bin/find $CTDB_BASE/state/periodic_vacuum -mmin +$CTDB_VACUUM_PERIOD | wc -l` -eq 1 ] && {
# vacuum the databases
touch $CTDB_BASE/state/periodic_vacuum
periodic_vacuum
}
2007-05-29 07:01:31 +04:00
esac
2007-06-01 14:54:26 +04:00
# all OK
exit 0