#! /bin/sh
### BEGIN INIT INFO
# Provides:          mpdscribble
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: mpdscribble initscript
# Description:       This script starts Music Player Daemon Audioscrobbler Client as daemon.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mpdscribble
NAME=mpdscribble
DESC="Music Player Daemon Audioscrobbler Client"
PIDFILE=/var/run/$NAME.pid

# user which will run this daemon
USER=mpdscribble
GROUP=mpdscribble

test -x $DAEMON || exit 0

# Include mpdscribble defaults if available
if [ -f /etc/default/mpdscribble ] ; then
	. /etc/default/mpdscribble
fi

. /lib/lsb/init-functions

case "$1" in
  start)
    log_daemon_msg "Starting $DESC" $NAME
	start-stop-daemon --chuid $USER:$GROUP --start --quiet \
		--make-pidfile --pidfile $PIDFILE \
		--background --exec $DAEMON -- $DAEMON_OPTS
    log_end_msg $?
	;;
  stop)
    log_daemon_msg "Stopping $DESC" $NAME
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--exec $DAEMON
    RET=$?
    rm -f $PIDFILE
    log_end_msg $RET
	;;
  restart|force-reload)
    sh $0 stop
    sleep 1
    sh $0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
