#!/bin/sh
#
# coherence	An UPnP/DLNA MediaServer
#
# chkconfig: 345 90 56
# description: An UPnP/DLNA MediaServer
# processname: coherence
# securlevel: 80
#
### BEGIN INIT INFO
# Provides: coherence
# Default-Start: 3 4 5
# Required-Start: $network messagebus
# Required-Stop: $network messagebus
# Short-Description: Starts the coherence server
# Description: An UPnP/DLNA MediaServer
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/rc.d/init.d/functions

PROGNAME=coherence
CONFIGFILE=/etc/coherence/coherence.conf
LOGFILE=/var/log/coherence
PIDFILE=/var/run/coherence.pid
LOCKFILE=/var/lock/subsys/coherence

RETVAL=0

#
# See how we were called.
#

start() {
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- python /usr/bin/$PROGNAME -d -c $CONFIGFILE -l $LOGFILE
	RETVAL=$?
	return $RETVAL
}

stop() {
	stop_daemon --lockfile "$LOCKFILE" --expect-user root -- $PROGNAME
	RETVAL=$?
	return $RETVAL
}

reload()
{
	msg_reloading $PROGNAME
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- $PROGNAME
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- $PROGNAME
		RETVAL=$?
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
		RETVAL=1
esac

exit $RETVAL
