Icecast2 is an audio streaming application, very popular is the early 2000’s. It allowed anyone with a simple server and decent bandwidth to stream mp3’s and other audio formats, radio station style (preset playlist, no skipping/ffwd/or rev).

It’s fallen out of favor for more popular streaming services, but its still available for people to use. I run an Icecast2 server playing 12 seasons of Cayenne Chris Conroy’s fantastic adult comedy Teknikal DiffiKulties (or Tekdiff for short) at radio.einherjar.org. My (and many other people’s) issue is the second program to make Icecast2 to work is Ices2. Icecast2 is the server, but Ices2 does the grunt work by reading the playlist, grabbing the correct audio file and then feeding the audio stream to Icecast.

Icecast when installed, it drops a startup service file in /etc/init.d called icecast2 (duh). It works perfectly; reboot the system, and icecast starts, no problem. Unfortunately when you install Ices2, it doesn’t add a startup service file, meaning you have to manually start it every time you reboot the hardware or when the server goes down. I’ve scoured the web trying all different ways to get Ices2 to start AFTER Icecast2 is started and ready to accept the stream. Nothing worked. I finally came up with my own solution, and I’m sharing it here. What I did was modify the original /etc/init.d/icecast2 file:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          icecast2
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Icecast2 streaming media server
# Description:       Starts the icecast audio streaming server daemon
### END INIT INFO
#
# icecast2 <Revised>
#
#               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#               Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
#               Further modified by Keegan Quinn <ice@thebasement.org> for use with Icecast 2
#               Further modified by Michael Bapst <lynxsilver@gmail.com> for use with IceS2
#
#               Copy to /etc/init.d
#               systemctl {enable|disable|start|stop|status} icecast2
#
#               Notes: When re/booting, wait or sleep 5 doesn't work. sleep 10 seems excessive,
#               but it works. Since I'm using IceS2 with a playlist, its basically set and forget.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/icecast2
DAEMON2=/usr/bin/ices2
NAME=icecast2
DESC="streaming media server"

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# Defaults
CONFIGFILE="/etc/icecast2/icecast.xml"
CONFIGFILE2="/etc/ices.xml"
CONFIGDEFAULTFILE="/etc/default/icecast2"
USERID=icecast2
GROUPID=icecast

# Reads config file (will override defaults above)
[ -r "$CONFIGDEFAULTFILE" ] && . $CONFIGDEFAULTFILE

set -e

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" "$NAME"
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE > /dev/null
        sleep 10
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON2 -- $CONFIGFILE2 > /dev/null
        log_end_msg $?
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        # Send TERM after 5 seconds, wait at most 30 seconds.
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON2
        log_end_msg $?
        ;;
  reload|force-reload)
        log_daemon_msg "Reloading $DESC configuration" "$NAME"
        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON2
        log_end_msg $?
        ;;
  restart)
        log_daemon_msg "Restarting $DESC" "$NAME"
        # Send TERM after 5 seconds, wait at most 30 seconds.
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON2
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE > /dev/null
        sleep 10
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON2 -- -b -c $CONFIGFILE2 > /dev/null
        log_end_msg $?
        ;;
  status)
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

My changes are in BOLD/ITALIC. Basically I just copied the original start/stop code and added a 10 second delay between the two. I tried using the WAIT command and SLEEP 5, but neither of them worked, but SLEEP 10 works fine. If you want to fine tune the SLEEP command, feel free. You’ll need to modify
DAEMON2=/usr/bin/ices2
CONFIGFILE2=”/etc/ices.xml”

to fit your setup.

I hope this saves someone else from tearing their hair out, rebooting their servers over and over again trying to find a solution.

By Lynx

Born in the 70's. Grew up in Western NY. Happily married, and has 2 children. Lives in Connecticut.