HOWTO Restart shoutcast if inbound stream is lost

This is a simple way to get Shoutcast restarted (tested in Ubuntu 8.04) if the inbound stream is lost. You need Lynx installed for this to work, there might be better ways of achieving the same result though. To install Lynx:


$ sudo apt-get install lynx

Put in file shoutcast_supervisor.sh in /usr/bin:

#!/bin/bash
ONLINE=$(lynx -dump localhost:8000 | grep "Stream is up" | wc -l)
if [ "$ONLINE" -eq "0" ]
then
logger -i Inbound connection not found. Restarting Shoutcast.
/etc/init.d/shoutcast restart
fi

Change ownership, group and execution:

$ sudo chown root /usr/bin/shoutcast_supervisor.sh
$ sudo chgrp root /usr/bin/shoutcast_supervisor.sh
$ sudo chmod +x /usr/bin/shoutcast_supervisor.sh

Add the script to cron.d your preferred way, I do it in /etc/cron.d in a file name shoutcast_supervisor:

0 * * * * root /usr/bin/shoutcast_supervisor.sh
15 * * * * root /usr/bin/shoutcast_supervisor.sh
30 * * * * root /usr/bin/shoutcast_supervisor.sh
45 * * * * root /usr/bin/shoutcast_supervisor.sh

Restart cron:

$ sudo /etc/init.d/cron restart

…and the script is run every 15 minutes and will restart the Shoutcast daemon if the inbound connection was lost. Change the interval if you need to check more often. Sometimes this solves connection problems. Check the syslog for any message that the daemon was restarted, like:

$ tail /var/log/syslog

HOWTO: Install Shoutcast 1.9.8 on Ubuntu 8.0.4

If you want to stream your own radio station, Shoutcast is an easy solution. This little HOWTO focus only on the server part, and not on the actual audio/feeding client part. I recommend reading ShoutCast Streaming for beginners and Streaming radio with ShoutCast and WinAmp to get the hang of the audio part.

Install

Download the tarball from shoutcast.com.


$ tar -xvf sc_serv_1.9.8_Linux.tar.gz
$ sudo cp sc_serv_1.9.8_Linux/sc_serv /usr/sbin
$ sudo mkdir /etc/shoutcast
$ sudo cp sc_serv.conf /etc/shoutcast

Automatic start

This will make shoutcast start when the server starts. Download the initscript (which I have modified to work in Ubuntu 8.04, source script here).


$ sudo cp shoutcast /etc/init.d/shoutcast
$ sudo update-rc.d /etc/init.d/shoutcast defaults

Check settings

The default sc_serv.conf says logging should go to the current directory. I changed the lines:

LogFile=sc_serv.log
...
W3CLog=sc_w3c.log

into:

LogFile=/var/log/sc_serv.log
...
W3CLog=/var/log/sc_w3c.log

Also, make sure you set a password on the line saying:

Password=changeme

Firewall

If you have a locally installed firewall, you have to open up two ports. First the port mentioned in sc_serv.conf on the line saying:

PortBase=8000

The second is the PortBase + 1, i.e. in the default example above it is 8001. The 8001 port is used to receive data from Winamp or other audio streaming feeder and the 8000 port is used to send streaming audio to listening clients. Make sure both ports are open for TCP and UDP. And don’t forget any hardware firewalls, they have to be opened too.

Restart

Restart the server or do:

$ sudo /etc/init.d/shoutcast start

and try opening localhost:8000 in your browser and you should see the (in-)famous Shoutcast page.