#!/bin/sh
#
# Because this stuff is still pretty young, you may wish to run the
# server using this script.  It'll notify if the server crashes and
# restart it after a couple of minutes.  It also puts the core in a known
# place and mails you any output generated by the terminal process.
#
# run it as  'run_daemon msqld' to run the mSQL engine.
#
#					bambi@Bond.edu.au

INST_DIR=/usr/local/Minerva
ADMIN="you@some.machine"
PROG=$1

if test ! -d "${INST_DIR}/debug"
then
	mkdir ${INST_DIR}/debug
fi

if test ! -d "${INST_DIR}/debug/${PROG}"
then
	mkdir ${INST_DIR}/debug/${PROG}
fi

while :
do
	cd ${INST_DIR}/debug/${PROG}
	${INST_DIR}/bin/${PROG} > output 2>&1
	echo "Program : ${PROG}
Time : `date`
Program Output
--------------

" > mail.tmp
	cat output >> mail.tmp
	/usr/ucb/mail -s "Minerva Daemon Crash Report" ${ADMIN} < mail.tmp
	sleep 15
done
