#!/bin/bash
#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright The DBT-2 Authors
#

if [ "x" = "x${DBT2DATADIR}" ]; then
	echo "ERROR: DBT2DATADIR must be set"
	exit 1
fi

LOGFILE="dbt2.log"
OUTDIR="."
HOSTNAME=`hostname`

while getopts "fo:p:s:" OPT; do
	case ${OPT} in
	f)
		if [ -f "${DBT2DATADIR}/${HOSTNAME}.pid" ]; then
			rm ${DBT2DATADIR}/${HOSTNAME}.pid
		fi
		;;
	o)
		OUTDIR=$OPTARG
		;;
	p)
		DEFAULTS_FILE=${OPTARG}
		DEFAULTS_FILE_ARG="--defaults-file=${DEFAULTS_FILE}"
		;;
	esac
done

if [ -f "${DBT2DATADIR}/${HOSTNAME}.pid" ]; then
	echo "MySQL pid file '${DBT2DATADIR}/${HOSTNAME}.pid' already exists."
	exit 1
fi
nohup mysqld_safe ${DEFAULTS_FILE_ARG} \
		--log-error=${OUTDIR}/${LOGFILE} > /dev/null 2>&1 &
sleep 10

exit 0
