#! /bin/sh

DAEMON=/usr/sbin/epos
NAME="epos"
INIT_CONFIG_FILE=/etc/default/epos

test -f $DAEMON || exit 0
if test -f $INIT_CONFIG_FILE; then
  . $INIT_CONFIG_FILE
fi

set -e

SSD_OPTIONS="--quiet --oknodo --name $NAME --exec $DAEMON"

case "$1" in
  start)
    echo -n "Starting $NAME"
    start-stop-daemon --start --chuid epos $SSD_OPTIONS $EPOS_DAEMON_START_OPTIONS
    echo "."
    ;;
  stop)
    echo -n "Stopping $NAME"
    start-stop-daemon --stop $SSD_OPTIONS
    echo "."
    ;;
  restart)
    echo -n "Restarting $NAME"
    start-stop-daemon --stop $SSD_OPTIONS
    sleep 1
    start-stop-daemon --start --chuid epos $SSD_OPTIONS $EPOS_DAEMON_START_OPTIONS
    echo "."
    ;;
  force-reload)
    if start-stop-daemon --test --quiet --start --exec $DAEMON >/dev/null; then
      echo "$NAME not running."
    else
      $0 restart
    fi
    ;;
  reload)
    cat<<EOF

    The text-to-speech server does not support reloading its
    configuration files without stopping.  Use \`force-reload' or
    \`restart' to stop and restart the daemon.

EOF
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}"
    exit 1
    ;;
esac

exit 0
