shoutcast + monitoring + restart + script + cron

Shoutcast servers which are running on shared hosts usually get shut down quite frequently by procwatch. While it is important to stay within system limits it is also important to have those servers running till you shift to dedicated hosting 😀
Here’s a quick and dirty shell script to monitor and restart shoutcast services. Drop it in cron to run every 15 minutes and you will never have to worry about your shoutcast going down.


#!/bin/bash
### Script to restart shoutcast server/transcoder when it's down
### Imtiaz a Khan http://blog.netbrix.net on 21 May 2007

prcs=`ps -ef | grep “sc_serv\|sc_trans” | grep -v grep > /tmp/monitor.log && cat /tmp/monitor.log | tr -s ” ” | cut -d” ” -f2,8 | grep -v grep | wc -l`
if [ ! $prcs ] || [ $prcs -lt 4 ]
then
/usr/bin/killall sc_trans_linux
/usr/bin/killall sc_serv
nohup sc_serv &
nohup sc_serv sc_serv_low.conf &
cd sc_trans_040
make_playlist
nohup sc_trans_linux &
nohup sc_trans_linux sc_trans_low.conf &

###Send out the mails to inform
echo “shoutcast services restarted at `date`”| mail -s “ALARM: shoutcast services on `hostname`” khanimtiaz@gmail.com
#echo “shoutcast services restarted at `date`”| mail -s “ALARM: shoutcast services on `hostname`” youremailid
else
echo “shoutcast services running fine on `date`”| mail -s “OK: shoutcast services on `hostname`” khanimtiaz@gmail.com
#echo “shoutcast services running fine on `date`”| mail -s “OK: shoutcast services on `hostname`” youremailid
fi

Make sure you replace the paths to the binaries and email ids. Also after a point getting a “everything OK” mail every 15 minutes gets irritating so just comment out the lines in the else portion when you’re happy with the script.

This script can be modified to monitor many other services that you’re running and facing problems with. Please Contact us for implementation on your server or for modifications.

Leave a Reply

Your email address will not be published. Required fields are marked *