#! /bin/sh

### BEGIN INIT INFO
# Provides:          epos
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: epos
# Description:       epos
### END INIT INFO

DAEMON=/usr/bin/eposd
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 --exec $DAEMON"

case "$1" in
  start)
    echo -n "Starting $NAME"
    start-stop-daemon --start --chuid epos --name $NAME $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 --name $NAME $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
