#!/bin/sh
#
# icecast	This shell script takes care of starting and stopping icecast
#
# chkconfig:	345 96 24
# description:	Icecast is an Internet audio broadcasting system based on
#		MPEG audio technology.

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

# Get network config
. /etc/sysconfig/network


# Get service config - may override defaults
[ -f /etc/sysconfig/icecast ] && . /etc/sysconfig/icecast

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_Network_Down icecast
	exit 1
fi

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/icecast ]; then
		# Our daemon function doesn't have --shell option!
		su icecast -s /bin/sh -c 'icecast -b' > /dev/null
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/icecast
	else
		msg_Already_Running Icecast
		exit 1
	fi
        ;;
  stop)
        # Stop daemons.
	if [ -f /var/lock/subsys/icecast ]; then
		msg_stopping icecast
		killproc icecast
		rm -f /var/lock/subsys/icecast >/dev/null 2>&1
	else
		msg_Not_Running Icecast
		exit 1
	fi	
        ;;
  restart)
        $0 stop
	$0 start
        ;;
  reload)
	if [ -f /var/lock/subsys/icecast ]; then
		msg_show Icecast
		msg_reload
		busy
		killproc icecast -HUP
		deltext
		ok		
	else
		msg_Not_Running Icecast
		exit 1
	fi
	;;
  force-reload)
  	# if program allows reloading without stopping
	$0 reload
	exit $?

	# or if it doesn't
	$0 stop && $0 start
	exit $?
	;;
  status)
	status icecast
	exit $?
        ;;
  *)
	msg_usage "$0 {start|stop|status|restart|reload|force-reload}"
        exit 1
esac

exit $RETVAL
