#! /bin/sh
#
# Author: Davide Lucchesi <odiobill@despammed.com>, 2003
#
# /etc/init.d/mpd
#
# and its symbolic link
#
# /usr/sbin/rcmpd
#
# System startup script for the Music Player Daemon.
#
### BEGIN INIT INFO
# Provides: mpd
# Required-Start: $network $remote_fs
# Should-Start: alsasound icecast
# Required-Stop: $network
# Should-Stop: alsasound icecast
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: This script takes care of managing the Music Player Daemon
### END INIT INFO

. /etc/rc.status

# Reset status of this service
rc_reset

MPD_BIN="/usr/bin/mpd"
MPD_CFG="/etc/mpd.conf"
MPD_PID="/var/lib/mpd/mpd.pid"
test -x $MPD_BIN || {
	echo "$MPD_BIN not installed";
	if [ "$1" = "stop" ] ; then
		exit 0
	else
		exit 5
	fi
	}

case "$1" in
	start)
		echo -n "Starting mpd "
		startproc $MPD_BIN $MPD_CFG
		rc_status -v
		;;
	stop)
		test -e $MPD_PID || {
		echo "$MPD_PID doesn't exist!"
		exit 0
		}
		echo -n "Shutting down mpd "
		$MPD_BIN --kill
		rc_status -v
		;;
	try-restart)
		$0 status
		if test $? = 0; then
			$0 restart
		else
			rc_reset
		fi
		rc_status
		;;
	restart)
		$0 stop
		$0 start
		rc_status
		;;
	status)
		echo -n "Checking for mpd: "
		checkproc $MPD_BIN
		rc_status -v
		;;
	*)
		echo "Usage: $0 {start|stop|try-restart|restart|status}"
		exit 1
		;;
esac
rc_exit
