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 in /usr/bin:

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

Change ownership, group and execution:

$ sudo chown root /usr/bin/
$ sudo chgrp root /usr/bin/
$ sudo chmod +x /usr/bin/

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/
15 * * * * root /usr/bin/
30 * * * * root /usr/bin/
45 * * * * root /usr/bin/

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