#! /bin/sh
### BEGIN INIT INFO
# Provides:          odysseus
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start/stop Odysseus Server
### END INIT INFO

USERNAME=odysseus

do_start() {
        su $USERNAME -l -c "screen -dmS odysseus /opt/odysseus/odysseus"
}

do_stop() {
        su $USERNAME -c  "screen -p 0 -S odysseus -X quit"
}

case "$1" in
    start)
                echo "Starting Odysseus ..."
                do_start
        ;;
    stop)
                echo "Stopping Odysseus ..."
                do_stop
        ;;
        restart)
                echo "Restarting Odysseus ..."
                do_stop
                do_start
                ;;
    *)
        echo "Usage: /etc/init.d/odysseus {start|stop}"
        ;;
esac

exit 0
