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

### BEGIN INIT INFO
# Provides: mt-daapd daap
# Required-Start: $local_fs $remote_fs $network $time
# Required-Stop: $local_fs $remote_fs $network $time
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Apple's DAAP protocol implementation
# Description: mt-daapd is a daemon which provides basic
#  functionality of Apple's media library (or ITunes music
#  sharing)
### END INIT INFO

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

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

PIDFILE=/var/run/$prog.pid
LOCKFILE=/var/lock/subsys/$prog

[ -f $conf ] || exit 0

RETVAL=0

start() {
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" -- $prog -m -y -c $conf 
	RETVAL=$?
	return $RETVAL
}

stop() {
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" $prog
	RETVAL=$?
	return $RETVAL
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	condstop)
		[ -e $LOCKFILE ] && $0 stop
		;;
	restart|reload)
		stop
		start
		RETVAL=$?
		;;
	condrestart)
		[ -e $LOCKFILE ] && $0 restart
		;;
	status)
		status --pidfile $PIDFILE
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|condrestart|status}"
		exit 1
esac

exit $RETVAL

