#!/bin/sh

APP_PID=/var/run/cz300-arcanix.pid

start() {
    MODE=$(uci -q get "ae_ms.arcanix.mode")
    if [ "$MODE" = "enabled" ]; then
        cd /barix/apps/epic-sip/
        barix-wd --pid-file=$APP_PID --timeout=5 --background --start -- \
            lua cz300-arcanix.lua
    fi

}

stop() {
    if [ -f $APP_PID ]; then
        barix-wd --pid-file=$APP_PID --stop --wait
    fi
}


# See how we were called.
case "$1" in
  start)
    start
    ;;
    
  stop)
    stop
    ;;

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

exit $?

