#!/bin/sh
#
# festival    This shell script takes care of starting and stopping Festival.
#
# chkconfig:   2345 64 36
# description: Run Festival as a server
# processname: festival
#
# To configure, edit /etc/festival/festival_server.scm
PORT="1314"
LOGDIR="/etc/festival"
CONFIG=""
if [ -f "/etc/festival/festival.scm" ]; then
	CONFIG="/etc/festival/festival.scm"
fi


# Source function library.
. /etc/rc.d/init.d/functions

prog="festival"

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1

RETVAL=0


start() {
	echo -n $"Starting ${prog}: "
	/usr/bin/festival_server -p "${PORT}" -l "${LOGDIR}" -c "${CONFIG}" > /dev/null 2>&1 &
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		success
		touch /var/lock/subsys/${prog}
	else
		failure
		RETVAL=1
	fi
	echo
	return $RETVAL
}	

stop() {
	echo -n $"Stopping ${prog}: "
	/usr/bin/festival_server_control -p "${PORT}" -l "${LOGDIR}" exit
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		success
		rm -f /var/lock/subsys/${prog}
	else
		failure
	fi
	echo
	return $RETVAL
}	

restart() {
	echo -n $"Stopping ${prog}: "
	/usr/bin/festival_server_control -p "${PORT}" -l "${LOGDIR}" restart
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		success
	else
		failure
	fi
	echo
}	

rhstatus() {
	status ${prog}
	return $?
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/${prog} ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|status|condrestart}"
	exit 2
esac

exit $?
