#!/bin/sh -e

### BEGIN INIT INFO
# Provides:          kgateway
# Required-Start:    khompdrv k3lserver +networking
# Required-Stop:     khompdrv k3lserver
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Khomp Gateway
### END INIT INFO



kgateway_helpline="Supported actions: start|stop|restart|force-start|force-stop|status|validate-config|help"

case "$1"
in
    start|force-start|"")
        /usr/sbin/kgateway start 
    ;;
    
    stop|force-stop)
        /usr/sbin/kgateway stop
    ;;
    
    restart)
        /usr/sbin/kgateway stop
        sleep 5
        /usr/sbin/kgateway start
    ;;

    status)
        if pidof kgateway 1>/dev/null
        then
            echo "running"
            exit 0
        else
            echo "not running"
            exit 1
        fi
    ;;

    validate-config)
        /usr/sbin/kgateway --validate-config
        exit $?
    ;;
    help)
        echo "${kgateway_helpline}"
        exit 0
    ;;

    *)
        echo "ERROR: Unknown action! ${kgateway_helpline}"
        exit 1
    ;;

esac
