1. Introduction
I really didn't understand how icecast worked when I first decided that I wanted a streaming audio server. After pulling a bunch of information of off the net I learned that there are about 3,000 different ways to stream audio and half of the howto's telling you what to do are either out of date or just plain wrong. I finally figured out how to get a server set up and decided to document the steps I took. This howto should provide you with the steps required to set up icecast (the streaming server that clients connect to) and ices (the application that streams audio to icecast). Please feel free to provide comments and corrections and I'll update this document accordingly.
Your streaming audio server will stream audio to both a local LAN or the Internet. With this fact in mind, this howto will attempt to guide the user to the most secure installation of icecast and ices reasonably possible. If you decide to undo the security built into this howto and run icecast or ices as root, please consider the consequences should someone compromise your icecast server.
Important: This howto was written for icecast-2 and ices-2. Previous versions of icecast and ices streamed audio using the MP3 format. As of version 2 ices now only supports the OGG format while icecast-2 still retains the ability to stream MP3. This may impact which clients can listen to your stream. If you require a MP3 stream you might want to look at Muse. I have included instructions for connecting Muse to icecast at the end of this howto. For a nifty MP3 to OGG converter, check out Oggasm.
2. Installing icecast and ices
USE Flags
Icecast can use the curl USE flag but this howto will not use it.
Installation
Both icecast and ices are currently in the Portage tree and should be straight forward to set up.
Code Listing 2.1: Emerging necessary packages
Code: Select all
# emerge -v icecast icesBecause icecast listens for client connections over a network we want to be very careful. If we run icecast as root and someone finds a flaw in it that allows an attacker to gain shell access, they will have a root shell to the system. To help avoid this situation we will run both icecast and ices as an unprivileged user: icecast. If someone compromises icecast and gains a shell to the system they will not automatically gain superuser access.
Code Listing 2.2: Creating the icecast user
Code: Select all
# groupadd icecast
# useradd icecast -m -g icecast -G users,wheel,audio -s /bin/bash
# passwd icecast
Code Listing 2.3: Configuring icecast
Code: Select all
# su - icecast
$ mkdir log
$ cp /etc/icecast2/icecast.xml .
Code Listing 2.4: Changes to icecast.xml
Code: Select all
<source-password>$passwd</source-password>
<relay-password>$passwd</relay-password>
<admin-password>$passwd</admin-password>
<hostname>$hostname</hostname>
<logdir>/home/icecast/log</logdir>
<!-- # Remove
<changeowner>
<user>icecast</user> # Change to icecast
<group>icecast</group> # Change to icecast
</changeowner>
--> # Remove
Code Listing 2.5: Starting icecast
Code: Select all
$ exit
# icecast -b -c /home/icecast/icecast.xml
Code Listing 2.6: Verifying icecast startup
Code: Select all
[2004-07-19 01:06:32] INFO main/main icecast server started
At this point, we've got icecast up and running. Icecast is now ready to receive the music stream from ices. Let's configure ices:
Code Listing 2.7: Configuring ices
Code: Select all
# su - icecast
$ cp /etc/ices2/ices-playlist.xml.dist ./ices-playlist.xml
Code Listing 2.8: Changes to ices-playlist.xml
Code: Select all
<background>1</background>
<logpath>/home/icecast/log</logpath>
<hostname>$hostname</hostname>
<password>$passwd</password>
<param name="file">/home/icecast/playlist.txt</param>
<mount>/$stream_name.ogg</mount> # Must include .ogg
Starting ices
Now that we have ices and icecast configured you will need to create a playlist for ices to stream to icecast. In this howto we've chosen /home/icecast/playlist.txt file to hold our playlist. The playlist is a text file with one absolute path per OGG file per line. We can create a playlist from an existing directory of OGG files:
Code Listing 2.9: Quick creation of a playlist
Code: Select all
$ find $ogg_dir -name *.ogg -print > playlist.txt
Now let's start ices as the icecast user:
Code Listing 2.10: Starting ices
Code: Select all
$ ices ./ices-playlist.xmlIf you hear your stream, congratulations! You now have a streaming audio server. After you're done strutting your stuff to your new music stream, close down ices and icecast and proceed to the next section where we will create startup and shutdown scripts for ices and icecast.
Code Listing 2.11: Hard shutdown of ices and icecast
Code: Select all
$ exit
# killall ices
# killall icecastWhen you emerge ices and icecast Portage does not create startup or shutdown scripts for you. You can use the following scripts to start and stop ices and icecast:
Code Listing 3.1: /etc/init.d/ices
Code: Select all
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
depend() {
need icecast net
use dns
}
start() {
ebegin "Starting ices"
start-stop-daemon --start --chuid icecast --quiet --exec /usr/bin/ices \
-- /home/icecast/ices-playlist.xml >/dev/null 2>&1
eend $?
}
stop () {
ebegin "Stopping ices"
start-stop-daemon --stop --retry 5 --quiet --exec /usr/bin/ices
eend $?
}
Code: Select all
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
depend() {
need net
use dns
}
start() {
ebegin "Starting icecast"
start-stop-daemon --start --quiet --exec /usr/bin/icecast \
--background -- -b -c /home/icecast/icecast.xml >/dev/null 2>&1
eend $?
}
stop () {
ebegin "Stopping icecast"
start-stop-daemon --stop --retry 5 --quiet --exec /usr/bin/icecast
eend $?
}
Code Listing 3.3: Starting icecast and ices at boot
Code: Select all
# rc-update add ices default
4. Installing and configuring muse
So the OGG format just won't work for you? Well there is a way to stream MP3 formatted streams using muse and this section will demonstrate how to hook up muse to icecast. I strongly recommend that you follow the previous sections and get icecast and ices working even if you do not want to stream music using the OGG format.
Note: Muse is limited in its abilities to play user created playlists. As far as I can tell there is no way to randomize a playlist at the time it is being streamed. This means that muse will play songs in the order they are listed in your playlist. Also, muse does not send information regarding the current song to icecast.
Important: Muse is a gruff little bear to deal with. It doesn't like being detached from a TTY and has no built-in ability to migrate itself to the background. It also does not have an option to write its logs to a file; it wants to write to standard error. This means that while this howto is designed with logging in mind, it just doesn't work so you will not get logs from muse when started with this howto's startup script. Feedback and suggestions are welcome.
USE Flags
Muse can use the following USE flags: debug gtk ncurses. This howto does not use any of these flags.
Installation
Muse is in Portage and installation should be straight forward to install:
Code Listing 4.1: Installing muse
Code: Select all
# emerge -v muse
Code Listing 4.2: Quick creation of a playlist for muse
Code: Select all
# su - icecast
$ find $mp3_dir -name *.mp3 -print > playlist.pls
Code Listing 4.3: /etc/init.d/muse
Code: Select all
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
depend() {
need icecast net
use dns
}
start() {
ebegin "Starting muse"
if [ -n "${MUSE_LOG}" -a ! -f "${MUSE_LOG}" ]; then
touch "${MUSE_LOG}"
chown icecast:icecast "${MUSE_LOG}"
fi
MUSE_OPTS="-C $MUSE_PLAYLIST -o -e mp3 -b ${MUSE_BITRATE} -q ${MUSE_QUALITY} -r ${MUSE_RATE} -c 2 -s ${MUSE_ICECAST_SERVER} -m ${MUSE_MOUNT} -p ${MUSE_ICECAST_PASSWD} -g cli"
start-stop-daemon --start --background --chuid icecast --quiet --exec /usr/bin/muse \
-- ${MUSE_OPTS} >"${MUSE_LOG}" 2>&1
eend $?
}
stop () {
ebegin "Stopping muse"
start-stop-daemon --stop --retry 5 --quiet --exec /usr/bin/muse
eend $?
}
Code Listing 4.4: /etc/conf.d/muse
Code: Select all
# Config file for muse
MUSE_BITRATE="128"
MUSE_QUALITY="9"
MUSE_RATE="44100"
MUSE_MOUNT="$stream_name.mp3"
MUSE_ICECAST_SERVER="localhost:8000"
MUSE_ICECAST_PASSWD="$passwd"
MUSE_PLAYLIST="/home/icecast/playlist.pls"
MUSE_LOG="/home/icecast/log/muse.log"
If you want muse and icecast to start on system boot, use rc-update:
Code Listing 4.5: Starting icecast and ices at boot
Code: Select all
# rc-update add muse default
You should be able to verify the muse to icecast connection by using your browser to view http://$hostname:8000/admin/stats.xsl. You should see the mount point /$stream_name.mp3 in the list of mount points. If your stream appears you should be able to connect to the stream by using the URL http://$hostname:8000/$stream_name.mp3.m3u.


