#!/bin/sh
#
# ices2		A streamer service for IceCast2 servers
#
# chkconfig: 2345 85 15
# description: ices2 streamer service for IceCast2 servers
# processname: ices2
# config:  /etc/ices-playlist.xml
# pidfile: /var/run/ices2.pid
#
### BEGIN INIT INFO
# Provides:          ices2
# Required-Start:    $syslog $network
# Required-Stop:     $syslog $network
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts ices2 streamer service
# Description:       starts ices2 - a streamer service to feed audio data
#                    into the IceCast2 server.
### END INIT INFO

WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/ices2.pid
LOCKFILE=/var/lock/subsys/ices2
USER=_ices
CONFIG=/etc/ices-playlist.xml
RETVAL=0

start()
{
	start_daemon --lockfile "$LOCKFILE" --make-pidfile --pidfile "$PIDFILE" --set-user "$USER" -- ices2 "$CONFIG"
	RETVAL=$?
	return $RETVAL
}	

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root --displayname ices2 su
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

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

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

exit $RETVAL
