#!/bin/sh
#/etc/init.d/festival
#
# Init script for starting Festival as a system-wide server process.
#
# Written by David Huggins-Daines <dhd@cepstral.com>
# LSBINITInfo by Kartik Mistry <kartik.mistry@gmail.com>
# LSB logging functions by David Härdeman <david@hardeman.nu>

### BEGIN INIT INFO
# Provides:          festival
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts Festival engine at boot time
# Description:       Init script for starting Festival TTS as a
#                    system-wide server process
### END INIT INFO

# Comment out the next line to start a Festival server at boot time.
exit 0

# NOTE: Not just anybody can connect to your server; the list of allowed
# hostnames is a regexp. Check /usr/share/festival/festival.scm for more
# helpful comments; add your settings to /etc/festival.scm.

set -e

DAEMON=/usr/bin/festival
REALPROC=/usr/bin/festival
NAME=festival

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

case "$1" in
  start)
    log_daemon_msg "Starting Festival server" "$NAME"
    start-stop-daemon --start --chuid festival --background \
		--exec $DAEMON -- --server
    log_end_msg 0
    ;;
  stop)
    log_daemon_msg "Stopping Festival server" "$NAME"
    start-stop-daemon --stop --oknodo --exec $REALPROC
    log_end_msg 0
    ;;
  restart|reload|force-reload)
    log_daemon_msg "Restarting Festival server" "$NAME"
    start-stop-daemon --stop --oknodo --exec $REALPROC
    start-stop-daemon --start --chuid festival --background \
		--exec $DAEMON -- --server
    log_end_msg 0
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
    exit 2
    ;;
esac

exit 0
