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