#!/bin/bash
#
# chkconfig: - 85 15
# description: mt-daapd is a multi-threaded DAAP server for iTunes
# processname: mt-daapd
# pidfile: /var/run/mt-daapd
#

# source function library
. /etc/init.d/functions

prog="mt-daapd"
conf="/etc/$prog.conf"

[ -f $conf ] || exit 0

RETVAL=0

start() {
	gprintf "Starting %s: " "$prog"
	$prog -m -y -c $conf &
	RETVAL=$?
	[ $RETVAL -eq 0 ] && success || failure
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mt-daapd
	return $RETVAL
}

stop() {
	gprintf "Shutting down %s: " "$prog"
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mt-daapd
	return $RETVAL
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		stop
		start
		RETVAL=$?
		;;
	condrestart)
		[ -e /var/lock/subsys/mt-daapd ] && $0 restart
		;;
	status)
		status $prog
		RETVAL=$?
		;;
	*)
		gprintf "Usage: %s {start|stop|restart|condrestart|status}\n" "$0"
		exit 1
esac

exit $RETVAL

