#!/bin/sh

start() {
  echo "Starting lora-packet-forwarder"
  start-stop-daemon \
  	--start \
	--background \
	--make-pidfile \
	--pidfile /var/run/lora-packet-forwarder.pid \
	--exec /tools/pkt_forwarder -- -c /etc/lora-packet-forwarder/config.json -g /dev/ttyS1
}

stop() {
  echo "Stopping lora-packet-forwarder"
  start-stop-daemon \
  	--stop \
	--oknodo \
	--quiet \
	--pidfile /var/run/lora-packet-forwarder.pid
}

restart() {
  stop
  sleep 1
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload)
    restart
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
