public:liquidsoap:setup_wbox

Build your own WBOX: web radio streaming station player/receiver

This tutorial covers a player or receiver of web radio streams at Ubuntu 10.04. It's purpose is to run a stable 24/7 service without user interaction. It consist of a liquidsoap and icecast configuration for streaming audio between 2 locations. Streaming is done by using OGG with a constant bitrate of 160kbit/s, but you use other codecs or settings, because streaming is done completely by using the flexible liquidsoap software.

required Hardware

You will need

  • one PC for recording and sending audio stream
  • one PC for receiving audio stream an playout

Each of the PCs should provide

  • one audio soundcard
  • one network interface, connected to the internet
  • one additional network interface (for multiple DSL upstream linking only)
  • BIOS support for start after power loss

Operating modes

Both modes require at least liquidsoap >= 1.0.0

recorder

The recorder uses live audio input from a soundcard, sends the audio stream to a local icecast server and saves the audio to file archive.

player

The player connects to the remote icecast stream and plays audio out to soundcard. If stream fails there a fallback to a secondary stream is used instead. If the second stream fails too, a local file will be played.

installation

installation is basically the same for recorder and player, there are only a few differences as described below.

BIOS settings

  • disable unused ALSA soundcards
  • enable start up after power failure

OS

  • install Ubuntu 10.04 LTS

create an Ubuntu user

  • create a user 'radio'
  • login
  • disable Ubuntu sound theme
  • disable Ubuntu playing audio at login screen

install liquidsoap

see here for all installation steps needed to get the latest version running.

setup log permissions to user radio

mkdir /usr/local/var/run/liquidsoap/
chown radio /usr/local/var/run/liquidsoap/
chmod 777 /usr/local/var/log/liquidsoap
chmod 777 /usr/local/var/log/liquidsoap/*

icecast setup

setup logs to user radio

mkdir /var/log/icecast
chown radio /var/log/icecast
chmod 777 /var/log/icecast
chmod 777 /var/log/icecast/*

add a mount to icecast configuration

vi /etc/icecast2/icecast.xml

<mount>
        <mount-name>/radio</mount-name>
        <username>user</username>
        <password>pass</password>
        <max-listeners>4</max-listeners>
        <hidden>1</hidden>
        <no-yp>1</no-yp>
</mount>

put set same mount, user and password settings at

/home/radio/radio/source/play/icecast.inc

autostart & hardening

To make icecast2 restart in case it fails or after power loss we define our own upstart jobs.

You can start or stop icecast2 yourself by

sudo start icecast2
sudo stop icecast2
  • disable old init.d script /etc/init.d/icecast
  • create upstart job
vi /etc/init/icecast2.conf
description	"icecast2"

start on (
	net-device-up
	and local-filesystems
)
stop on runlevel [016]

respawn

exec su - radio -c "/usr/bin/icecast2 -c /etc/icecast2/icecast.xml 2>&1 >>/var/log/icecast2/error.log"

setup user groups

add user 'radio' to following groups

  • audio
  • icecast
  • liquidsoap

ALSA setup

We made good experiences with MAYA ESI 44 soundcard with symmetric input/output. Other soundcards should work as well, but especially recording seems to be tricky at some cards at Ubuntu even today.

find ALSA device

aplay --list-devices

create virtual device to make sure to use alsa

vi /etc/asound.conf

pcm.liquidsoap {

        type plug
        slave { pcm "hw:0,0" }
}

use this device at play.liq

output.alsa(device="pcm.liquidsoap")

install WBOX scripts

download scipts and extract to /home/radio/ so there should be 2 directories: /home/radio/play and /home/radio/record.

PATCH: remove following line from /home/radio/play/output_vorbis.cbr.liq

restart=true,

add following lines to /home/radio/.profile to make some shortcuts available

alias wbox-home='echo "cd /home/radio/play";cd /home/radio/play'
alias wbox-restart='wbox-home;echo "sudo ./restart.sh";sudo ./restart.sh'
alias wbox-proc='wbox-home;echo "./status.h";./status.sh'
alias wbox-log='wbox-home;echo "./log.pl";./log.pl'
alias wbox-net='wbox-home;./net_traffic.pl'
wbox-proc

autostart & hardening

To make scripts restart if they fail or after power loss we define own upstart jobs for wbox scripts. depending on your usecase use player or recorder upstart job.

You can start or stop liquidsoap yourself by

sudo start liquidsoap
sudo stop liquidsoap

player

starts when network becomes active

vi /etc/init/liquidsoap.conf
description	"liquidsoap"

start on (
	net-device-up
	and local-filesystems
        and runlevel [2345]
)
stop on runlevel [016]

respawn

exec su - radio -c "liquidsoap /home/radio/play/play.liq"  2>&1 >>/var/log/liquidsoap/play.log

recorder

starts when local filesystems are mounted

vi /etc/init/liquidsoap.conf
description	"liquidsoap"

start on (
          local-filesystems
	  and runlevel [2345]
)

stop on runlevel [016]

respawn

exec su - radio -c "/usr/local/bin/liquidsoap /home/radio/record/play.liq  2>&1 >>/var/log/liquidsoap/play.log"

using multiple DSL routers to increase availability

You can connect 2 DSL routers to the system, in this case they should connect to different DSL providers. For details see http://wiki.ubuntuusers.de/Multiple_Uplink_Routing. You can enable this settings at the same system you are running the WBOX player at, but you will need a second network device for this.

system control

  • reboot after 3 seconds by kernel.panic = 3
  • do only swap on out of memory by vm.swappiness = 0
sudo vim /etc/sysctl.conf 

kernel.panic = 3
vm.swappiness = 1

create log file directories

mkdir /var/log/wunderbox
chmod 777 /var/log/wunderbox
chown radio /var/log/wunderbox
chmod 777 /var/log/wunderbox
chmod 777 /var/log/wunderbox/*

enable log rotation

/etc/logrotate.d/wunderbox

/var/log/wunderbox/*.log {
  compress
  rotate 5
  size 300k
  missingok
  notifempty
  sharedscripts
}

Impressum Datenschutz