#!/bin/sh

### BEGIN INIT INFO
# Provides:          mpdstartup
# 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
# Short-Description: starts the recpt1d
# Description: starts the mpdstartup (USER=volumio)
### END INIT INFO

# cp mpdstartup /etc/init.d
# cd /etc/init.d
# Auto Start , systemctl enable mpdstartup
# Stopped , systemctl disable mpdstartup

#MPDSTART=/var/www/html/mpdweb/shell/mpdstart.pl
MPDSTART=`find /var/www -name "mpdstart.pl"`
TASKNAME=mpdstart
USER=volumio

# define functions
start() {
	echo -n "${TASKNAME} init.\n"
	${MPDSTART} /dev/null 2>&1 &
	return 0
}
stop() {
	echo -n "${TASKNAME} term.\n"
	PID=`pgrep -f ${MPDSTART}`
	if [ "${PID}" != "" ] ; then
	 	echo ${MPDSTART} : ${PID}
 		kill -9 ${PID}
	fi
	return 0
}
restart() {
	stop
	start
}

case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		restart
	;;
	*)
	echo "Usage: $0 {start|stop|restart)\n"
	RETVAL=2
esac
