#! /bin/sh

APPLICATION_OPTS="-D/dev/ttyACM0 -c/etc/rp-display.properties"
APPLICATION_NAME="rp-display-controller"
APPLICATION_USER_NAME="Barix Display Controller Application"
APPLICATION_BIN=/usr/bin/$APPLICATION_NAME
APP_PID="/var/run/rp-display-controller.pid"



launch_application() {
    while [ ! -c /dev/ttyACM0 ]; do
        sleep 2
    done
    
    barix-wd --pid-file=$APP_PID --timeout=5 --background --start -- \
	    ${APPLICATION_BIN} ${APPLICATION_OPTS}

}

start() {
    launch_application&
}

stop() {
    barix-wd --pid-file=$APP_PID --stop 
}

restart() {
    stop
    start
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    ###rm -f $APP_STARTED_FLAG
    stop
    ;;
  restart|reload)
    restart
    ;;
  *)
    echo "Usage: $0 {start|stop|reload|restart}"
    exit 1
esac

exit $?
