Run Your Own Webradio Station With Icecast2 And Ices2 - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2007-02-15 18:05. ::

3 Install And Configure Ices2

To install Ices2, we run

apt-get install ices2

Next we create the directories /var/log/ices (for the Ices2 log files), /etc/ices2 (where we store our Ices2 configuration file), and /etc/ices2/music (where we store our .ogg files):

mkdir /var/log/ices
mkdir /etc/ices2
mkdir /etc/ices2/music

The Ices2 package comes with three sample configuration files, /usr/share/doc/ices2/examples/ices-alsa.xml, /usr/share/doc/ices2/examples/ices-oss.xml, and /usr/share/doc/ices2/examples/ices-playlist.xml. We use the latter one because we will create a playlist of local .ogg files that we want to stream to listeners. Therefore we copy that file to /etc/ices2:

cp /usr/share/doc/ices2/examples/ices-playlist.xml /etc/ices2

Next we edit /etc/ices2/ices-playlist.xml. Most default values should work, but we change <background>0</background> to <background>1</background> because we want Ices2 to run in the background (otherwise it would wait on the shell until you terminate it), we also change the data in the <metadata>...</metadata> section, we set the full path to our playlist file in the <input>...</input> section, and we set the correct source password for our Icecast2 server in the <instance>...</instance> section (you can also set the bitrate of your audio stream in that section):

vi /etc/ices2/ices-playlist.xml

<?xml version="1.0"?>
<ices>
    <!-- run in background -->
    <background>1</background>
    <!-- where logs, etc go. -->
    <logpath>/var/log/ices</logpath>
    <logfile>ices.log</logfile>
    <!-- 1=error,2=warn,3=info,4=debug -->
    <loglevel>4</loglevel>
    <!-- set this to 1 to log to the console instead of to the file above -->
    <consolelog>0</consolelog>

    <!-- optional filename to write process id to -->
    <!-- <pidfile>/home/ices/ices.pid</pidfile> -->

    <stream>
        <!-- metadata used for stream listing (not currently used) -->
        <metadata>
            <name>Example stream name</name>
            <genre>Example genre</genre>
            <description>A short description of your stream</description>
        </metadata>

        <!-- input module

            The module used here is the playlist module - it has
            'submodules' for different types of playlist. There are
            two currently implemented, 'basic', which is a simple
            file-based playlist, and 'script' which invokes a command
            to returns a filename to start playing. -->

        <input>
            <module>playlist</module>
            <param name="type">basic</param>
            <param name="file">/etc/ices2/playlist.txt</param>
            <!-- random play -->
            <param name="random">0</param>
            <!-- if the playlist get updated that start at the beginning -->
            <param name="restart-after-reread">0</param>
            <!-- if set to 1 , plays once through, then exits. -->
            <param name="once">0</param>
        </input>

                <!-- Stream instance
            You may have one or more instances here. This allows you to
            send the same input data to one or more servers (or to different
            mountpoints on the same server). Each of them can have different
            parameters. This is primarily useful for a) relaying to multiple
            independent servers, and b) encoding/reencoding to multiple
            bitrates.
            If one instance fails (for example, the associated server goes
            down, etc), the others will continue to function correctly.
            This example defines two instances as two mountpoints on the
            same server.  -->
        <instance>
            <!-- Server details:
                You define hostname and port for the server here, along with
                the source password and mountpoint.  -->
            <hostname>localhost</hostname>
            <port>8000</port>
            <password>password1</password>
            <mount>/example1.ogg</mount>

            <!-- Reconnect parameters:
                When something goes wrong (e.g. the server crashes, or the
                network drops) and ices disconnects from the server, these
                control how often it tries to reconnect, and how many times
                it tries to reconnect. Delay is in seconds.
                If you set reconnectattempts to -1, it will continue
                indefinately. Suggest setting reconnectdelay to a large value
                if you do this.
            -->
            <reconnectdelay>2</reconnectdelay>
            <reconnectattempts>5</reconnectattempts>

            <!-- maxqueuelength:
                This describes how long the internal data queues may be. This
                basically lets you control how much data gets buffered before
                ices decides it can't send to the server fast enough, and
                either shuts down or flushes the queue (dropping the data)
                and continues.
                For advanced users only.
            -->
            <maxqueuelength>80</maxqueuelength>

            <!-- Live encoding/reencoding:
                Currrently, the parameters given here for encoding MUST
                match the input data for channels and sample rate. That
                restriction will be relaxed in the future.
            -->
            <encode>
                <nominal-bitrate>64000</nominal-bitrate> <!-- bps. e.g. 64000 for 64 kbps -->
                <samplerate>44100</samplerate>
                <channels>2</channels>
            </encode>
        </instance>

        </stream>
</ices>

Afterwards put your .ogg files into the /etc/ices2/music directory (but take care about the licenses of the audio files you want to stream - you might have to pay money to get the right to stream them), e.g. with a tool like WinSCP.

Afterwards create the file /etc/ices2/playlist.txt and put the full paths to your .ogg files into it, one line per .ogg file:

vi /etc/ices2/playlist.txt

[...]
/etc/ices2/music/1vs0_JuniorGroove.ogg
/etc/ices2/music/1vs0_TheWavechangerSuperhero.ogg
[...]

Then start Ices2:

ices2 /etc/ices2/ices-playlist.xml

In the Icecast2 web interface you should now find a link to your new audio stream (Click to Listen -> http://192.168.0.100:8000/example1.ogg.m3u, but http://192.168.0.100:8000/example1.ogg works as well):

Open the link with your favourite audio player, for example WinAMP:

If you want to stop Ices2, just run

kill -9 `pidof ices2`

 

4 Modify The Icecast2 Init Script

Ices2 doesn't come with an init script which means we must start/stop it independently from Icecast2. Icecast2 comes with an init script which means it starts automatically at boot time, but Ices2 does not which can become annoying. Therefore we modify the Icecast2 init script and add sections for Ices2 to it.

The original Icecast2 init script looks like this:

vi /etc/init.d/icecast2

#! /bin/sh
#
# icecast2
#
#                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
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/icecast2
NAME=icecast2
DESC=icecast2

test -x $DAEMON || exit 0

# Defaults
CONFIGFILE="/etc/icecast2/icecast.xml"
CONFIGDEFAULTFILE="/etc/default/icecast2"
USERID=icecast2
GROUPID=icecast
ENABLE="false"

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

if [ "$ENABLE" != "true" ]; then
        echo "$NAME daemon disabled - read $CONFIGDEFAULTFILE."
        exit 0
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
        echo "$NAME."
        ;;
  reload|force-reload)
        echo "Reloading $DESC configuration files."
        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
        ;;
  restart)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE
        echo "$NAME."
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

We modify it so that it looks like this (I've added or modified the parts in red):

vi /etc/init.d/icecast2

#! /bin/sh
#
# icecast2
#
#                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
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/icecast2
NAME=icecast2
DESC=icecast2
ICES=/usr/bin/ices2
ICES_CONFIGFILE=/etc/ices2/ices-playlist.xml

test -x $DAEMON || exit 0

# Defaults
CONFIGFILE="/etc/icecast2/icecast.xml"
CONFIGDEFAULTFILE="/etc/default/icecast2"
USERID=icecast2
GROUPID=icecast
ENABLE="false"

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

if [ "$ENABLE" != "true" ]; then
        echo "$NAME daemon disabled - read $CONFIGDEFAULTFILE."
        exit 0
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE
        sleep 3
        start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --oknodo --quiet --exec $ICES

        start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
        echo "$NAME."
        ;;
  reload|force-reload)
        echo "Reloading $DESC configuration files."
        start-stop-daemon --stop --oknodo --quiet --exec $ICES
        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
        sleep 3
        start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE
        ;;
  restart)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --oknodo --quiet --exec $ICES

        start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
        sleep 3
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
                --exec $DAEMON -- -b -c $CONFIGFILE
        sleep 3
        start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE
        echo "$NAME."
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

Now Ices2 will start/stop/restart whenever Icecast2 does, and it will also start at boot time.

 

5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Martin Urbina (not registered) on Sat, 2012-01-21 18:04.

Buen día, Gracias por la guia!!!!

Lo he configurado con un servidor Ubuntu 11.04 (GNU/Linux 2.6.38-13-server x86_64)

y anda de maravilla, voy a seguir para darle un mejor uso.

Saludos, desde Tegucigalpa, Honduras C.A.

Submitted by Glen (not registered) on Sun, 2011-05-22 00:13.

I really don't know how to mount.

 What .ogg should I put?

Submitted by Fabho (not registered) on Wed, 2011-05-11 21:10.

Really easy and really simple isntruction.

 Thanks a lot

Submitted by dacosta67 (registered user) on Sun, 2011-03-27 21:20.

i am new with icecast and ice2 . i want to know why when i clique play , one song in the playlist play and stop? how can i have a continuous play with ice2.

Submitted by Anonymous (not registered) on Sun, 2011-03-27 21:14.

please i want to know how to configure a continuous play in ice2,Because we i click play it play one music and then it stop.I don't know why 

Submitted by Miguel (not registered) on Fri, 2010-04-16 03:55.

Soy de Chile. Has escrito un gran tutorial. Uso Ubuntu 9.10 y funciona muy bien.

Gracias!

 

I m from Chile. You wrote a great tutorial. I use Ubuntu 9.10 and the radio works very good.

Thanks!

Submitted by mitse (not registered) on Tue, 2009-07-21 22:20.

I have done all this procedure above but  the mount point  (.ogg file) that I put inside /etc/ices2/music directory does not appear in the icecast web interface ...

What can be wrong ...any  help please ?

Submitted by Anonymous (not registered) on Wed, 2009-12-02 20:03.
I also can not get the mount point to work. Any ideas where to start? Everything else seems to be fine
Submitted by Anonymous (not registered) on Thu, 2009-12-03 13:26.
Check the log files.
Submitted by Anonymous (not registered) on Mon, 2009-05-04 20:35.

Nice howto!

However, I get this:

stijn-desktop:/etc$ sudo /etc/init.d/icecast2 start
Starting icecast2: Starting icecast2
Detaching from the console
Server startup failed. Exiting
icecast2.

Please help.

Greets,

Stijn

Submitted by Anonymous (not registered) on Fri, 2009-04-03 02:12.
thanks
Submitted by Anonymous (not registered) on Fri, 2009-03-20 12:39.
Thank you so much! Very usefull :-)
Submitted by kotnik (registered user) on Thu, 2007-02-22 17:15.

This is awesome HOWTO. I'm sure many will find it useful.

Icecast2 is well written server, and it is easy to setup. Ices2 works flawlesly with playlists, but it takes some kung fu to make it sample from alsa device. But it can be done.

I just want to add two notes. First, it's bad pratice to stop programs with SIGKILL (-9). Ices2 dies easily, so there's no need to kill it in that way.

Second, here's a fast way to create a playlist from a directory full of oggs:

find  /etc/ices2/music -iname *.ogg > playlist.txt

Submitted by Anonymous (not registered) on Mon, 2008-11-03 01:50.
Awesome! Thanks!
Submitted by Shan (not registered) on Tue, 2009-10-13 09:32.

everithing work ok but ices2 stopt after 3 min! and start up at boot not work

system ubunto server please help!

adminarea work ok but listen not possible.