#!/bin/sh

APP_NAME="jdb_server.py"
APP_PATH="/barix/apps/jdb/"
APP_PID="/var/run/jdb_service.pid"

WD_BIN="barix-wd"

start() {
    cd ${APP_PATH}
    ${WD_BIN} --pid-file=${APP_PID} --timeout=5 --background --start -- /usr/bin/python3 ${APP_NAME} >/dev/null 2>&1
}

stop() {
    ${WD_BIN} --pid-file=${APP_PID} --stop --wait
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        stop
        start
        ;;
    *)

    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
