#!/bin/sh

# Avoid using root's TMPDIR
unset TMPDIR

[ -z "$CTDB_BASE" ] && {
    export CTDB_BASE="/etc/ctdb"
}

[ -z "$CTDB_VARDIR" ] && {
    export CTDB_VARDIR="/var/ctdb"
}

# Preseed default values
CTDB_NODES=/etc/ctdb/nodes
CTDB_LOGFILE=/var/log/log.ctdb

. /etc/sysconfig/ctdb

if [ -n "$CTDB_RECOVERY_LOCK" ] && [ ! -e "$CTDB_RECOVERY_LOCK" ] 
then
	echo "You have recloc file path \$CTDB_RECOVERY_LOCK set to \"$CTDB_RECOVERY_LOCK\" but the file does not exist."
	echo "CTDB daemon can not operate. Please see /etc/sysconfig/ctdb for details."
	exit 2
fi

if [ ! -f "$CTDB_NODES" ]
then
	echo "The NODES file $CTDB_NODES does not exist."
	echo "CTDB daemon can not operate. Please see /etc/sysconfig/ctdb for details."
	exit 2
fi

if [ ! -s "$CTDB_NODES" ]
then
	echo "The NODES file $CTDB_NODES is empty."
	echo "CTDB daemon can not operate. Please see /etc/sysconfig/ctdb for details."
	exit 2
else
	echo "The NODES file $CTDB_NODES exists and is not empty. Proceeding."
	echo "Check \"$CTDB_LOGFILE\" file if CTDB fails to start beyond this point."
fi

exit 0
