#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          WebTunnelAgent
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop macchina.io REMOTE device agent
### END INIT INFO

. /lib/lsb/init-functions

SERVICE=WebTunnelAgent
PIDFILE=/var/run/${SERVICE}.pid
DAEMON=/usr/local/sbin/$SERVICE
CONFIG=/etc/${SERVICE}.properties

if [ ! -x $DAEMON ] ; then
	echo "No $DAEMON executable found"
	exit 0
fi

start() {
	log_daemon_msg "Starting $SERVICE: "
	start-stop-daemon -S -p $PIDFILE -x "$DAEMON" -- --config=$CONFIG --pidfile=$PIDFILE --daemon
	log_end_msg $?
}

stop() {
	log_daemon_msg "Stopping $SERVICE: "
	start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
	log_end_msg $?
}

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

exit 0

