#!/bin/sh
#
# icecast:       Starts the Icesast media streamer
#
# chkconfig: 2345 90 10
# description: Starts and stops the Icesast media streamer at boot time and shutdown.
#
# processname: icecast
# config: /etc/icecast/icecast.conf
# hide: true

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

PIDFILE=/var/run/icecast/icecast.pid
LOCKFILE=/var/lock/subsys/icecast
RETVAL=0

start()
{
	echo -n "Starting Icecast media streamer: "
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user icecast -- icecast -b -c /etc/icecast.xml
	RETVAL=$?
	echo	
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	return $RETVAL
}

stop()
{
	echo -n "Shutting down Icecast media streamer: "
        stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user icecast -- icecast
		
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	echo -n "Reloading Icecast media streamer configuration: "
	stop_daemon --pidfile "$PIDFILE" --expect-user icecast -HUP icecast
	RETVAL=$?
	echo
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status icecast
		RETVAL=$?
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|status|reload|restart|condstop|condrestart}"
		RETVAL=1
esac

exit $RETVAL
