#! /bin/sh
### BEGIN INIT INFO
# Provides:          xlxd service
# Processname:       xlxd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the dstar reflector as a linux service
# Description:       dstar reflector by LX3JL
#                    start script by LX1IQ
### END INIT INFO


PATH=/sbin:/bin:/usr/sbin:/usr/bin

. /lib/lsb/init-functions

# change below settings according to your system
NAME="xlxd"
DAEMON="/xlxd/xlxd"
ARGUMENTS="XLX270 158.64.26.132"
PIDFILE="/var/log/xlxd.pid"
USER=root
GROUP=root

[ -f $DAEMON ] || exit 0

start () {

# start daemon

	echo -n "Starting $NAME: "
	start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background -- $ARGUMENTS
	RETVAL=$?
	echo
        sleep 4
        echo `pidof xlxd` > $PIDFILE
	return $RETVAL
}

stop () {
	echo -n "Stopping $NAME: "
	start-stop-daemon --stop --pidfile $PIDFILE
	RETVAL=$?
	echo
}

case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		stop
		start
	;;
	status)
                PIDID=`pidof xlxd`
		echo $DAEMON $NAME :
                if [ $PIDID -gt 0 ] 2>/dev/null;
            then
                echo running
            else
                echo not running
            fi

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

exit 0
