#!/bin/sh
#
#
# chkconfig: 2345 90 10
# description: This startup script runs any mojolicious application under hypnotoad
#

WITHOUT_RC_COMPAT=1

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

USER="nobody"
APP=""

SourceIfNotEmpty "/etc/sysconfig/hypnotoad"

[ -f "$APP" ] || exit

RETVAL=0

start()
{
    action "Starting hypnotoad service" true
    su - $USER -s /bin/sh -c "/usr/bin/hypnotoad $APP &> /dev/null"
}

stop()
{
    action "Stopping hypnotoad service" true
    su - $USER -s /bin/sh -c "/usr/bin/hypnotoad -s $APP &> /dev/null"
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop|condstop)
        stop
        ;;
    status)
        ;;
    reload|condreload)
        start
        ;;
    restart|condrestart)
        stop
        start
        ;;
    *)
        msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
        RETVAL=1

esac

exit $RETVAL
