[PATCH] Init Startup Scripts for Icecast

Claudius Zingerli <[email protected]>
Newsgroups gmane.comp.audio.icecast.devel
Message-ID <[email protected]>
Hi,

In order to automatically start icecast at system boot, I created a 
startup script for icecast (adapted from /etc/init.d/openssh).
In order to make this work, you need to create:

cat /etc/sysconfig/icecast

#Icecast service startup parameters
OPTIONS='-c /usr/local/etc/icecast.xml'

Adapt you icecast.xml to create a pid file in the standard location:
Instead of <pidfile>/usr/local/share/icecast/icecast.pid</pidfile> use: 
<pidfile>/var/run/icecast.pid</pidfile>

(or adapt the init script to look in /usr/local)

Then put the following code in /etc/init.d/icecast and mark it 
executable and do "chkconfig --add icecast" to register the service.

#!/bin/bash
#
# chkconfig: 2345 88 55
# Description: Icecast init.d script
# Adapted by zeuz from: openssh initd script


# Get function from functions library
. /etc/init.d/functions

# pull in sysconfig settings
[ -f /etc/sysconfig/icecast ] && . /etc/sysconfig/icecast

prog="icecast"
PID_FILE=/var/run/${prog}.pid
PROG_FILE=/usr/local/bin/${prog}
OPTIONS+=' -b'
RETVAL=0

# Start Icecast
start() {
         echo -n $"Starting ${prog}: "
#       echo -n $"${PROG_FILE} ${OPTIONS} >/dev/null 2>&1 && success || 
failure"
         ${PROG_FILE} ${OPTIONS} >/dev/null 2>&1 && success || failure
         RETVAL=$?
         [ "${RETVAL}" = 0 ] && touch /var/lock/subsys/${prog}
         echo
}

# Stop Icecast
stop() {
         echo -n $"Stopping ${prog}: "
         if [ -n "`pidfileofproc ${prog}`" ] ; then
                 echo "killproc ${prog}"
         else
                 failure $"Stopping ${prog}"
         fi
         RETVAL=$?
         # if we are in halt or reboot runlevel kill all running sessions
         # so the TCP connections are closed cleanly
         if [ "x${runlevel}" = x0 -o "x${runlevel}" = x6 ] ; then
                 killall ${prog} 2>/dev/null
         fi
         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/${prog}
         echo
}

### main logic ###
case "${1}" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   status)
         status -p $PID_FILE ${prog}
         RETVAL=$?
         ;;

   condrestart)
         if [ -f /var/lock/subsys/${prog} ] ; then
                 stop
                 sleep 3
                 start
         fi
         ;;
   restart|reload)
         stop
         start
         ;;
   *)
         echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
         RETVAL=1
esac

exit 0


I hope that helps. I think it might be useful. The code has been tested 
on RHEL 5. Maybe someone could put that file in a contrib directory. (or 
adapt the Makefile to automatically place the init script)
I'll open a ticket as soon as I get access to the trac repo.

Cheers

Claudius
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.