Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Reply
Thread Tools Search this Thread Display Modes
Old 30th July 2008, 18:58   #1
yigald
Junior Member
 
Join Date: May 2005
Posts: 8
Maintenance script

Hi

I hope I'm addressing the right forum.

I wrote a little shell script the checks if the shoutcast process is up and running, if it is not it kills what there is (if any) and restart. I'm running it in cron every minute

That is the restart script

Quote:
#!/bin/bash
cd <full path to your script folder>
a=`ps -x | grep -i sc_ | grep -v grep`
x1=`echo $a | awk '{print $1}'`
x2=`echo $a | awk '{print $12}'`
kill -9 $x1
kill -9 $x2
echo "killing PID $x1 $x2"
echo "killing PID ends successfully, loading radio...."
screen -A -m -d -S radio ./<your shoutcast script name>

And that is the watchdog script

Quote:
#!/bin/bash
clear
echo --------------------------------------------------------
echo
echo Current date is `date`
echo --------------------------------------------------------

##############################################################################
# Creating Variable for the watchdog script and writing to a file #
##############################################################################

wdpid=`ps -ef | grep -i radio_watchdog.sh | grep -v grep | grep -v ps | awk '{print $1}' | uniq `
echo
rm <full path>/watchdog*pid
echo $wdpid > <full path>/watchdog.$wdpid.pid
echo
echo pid of watchdog is $wdpid
touch radio_watchdog.sh
echo
##############################################################################
# checking if pid is exist for radio script #
##############################################################################


radio_proc=`ps -x | grep -i screen | grep -v grep | awk '{print $1}' `
if [ -z "$radio_proc" ]
then # $radio_proc is empty
if [ ${radio_proc+EMPTY} = EMPTY ]
then echo "radio_proc is empty, but set"
<full path>/radio_restart.sh
#<full path>/test.sh
else echo "radio_proc is not set"
fi
else # radio_proc contains value
echo "radio is running, radio pid is $radio_proc"
fi
echo
echo
echo
echo --------------------------------------------------------
cp <full path>/radio_watchdog.log <full path>/radio_watchdog.txt
echo
echo
echo
echo Log fils size (KB) and name >> <path to web site>/public_html/radio_watchdog.txt
echo ----------------------------- >> <path to web site>/public_html/radio_watchdog.txt
ls -lh *sc*.log* | awk '{print $5,$9 }' >> <path to web site>/public_html/radio_watchdog.txt
yigald is offline   Reply With Quote
Old 7th August 2008, 01:05   #2
fc*uk
Moderator
 
fc*uk's Avatar
 
Join Date: Dec 2005
Location: Atlantic Beach
Posts: 7,998
hey, this is both more efficient and more informative than the scripts that I use. Beautifully simple too.

Cheers and thanks for sharing. I'll make sure I reference this to everyone who comes asking from now on!
fc*uk is offline   Reply With Quote
Old 21st April 2009, 20:34   #3
yigald
Junior Member
 
Join Date: May 2005
Posts: 8
Radio-watchdog V1.4
---------------------
Code optimization and a little more

This script is running under cron every one minute which makes sure your stream (as long as there is a source) will be down only for one minute at the most

Here is the code:
[PHP]
#!/bin/bash

##############################################################################
# This script was written by Yigal Dekel (yigald@gmail.com) and can be used #
# freely as long as it is copied/used/implemented as it is. #
# Radio watchdog 1.4 #
##############################################################################

##############################################################################
# Creating General Variables #
##############################################################################
active_dir=radio/current

#file var will be used as a buffer
wd_log="radio_watchdog.txt"
web=$HOME/public_html/watchdog.log

#End of user config
#Starting to write to buffer
file="$file\n"
file="$file\n--------------------------------------------------------"
file="$file\nCurrent date is `date |awk '{print $1,$2,$3,$4}' `"
file="$file\n--------------------------------------------------------"
file="$file\nServer uptime is `uptime |awk '{print $3,$4}' `"
file="$file\n--------------------------------------------------------"

##############################################################################
# Creating Variable for the watchdog script and writing it to a file #
##############################################################################

wdpid=`ps -ef | grep -i radio_watchdog | grep -v grep | grep -v ps | awk '{print $1}' | uniq `
file="$file\n"

rm $HOME/$active_dir/watchdog*pid

echo $wdpid > $HOME/$active_dir/watchdog.$wdpid.pid
file="$file\n"

file="$file\npid of watchdog is $wdpid"
touch $HOME/$active_dir/radio_watchdog.sh
file="$file\n"


##############################################################################
# checking if pid is exist for radio script #
##############################################################################


radio_proc=`ps -x | grep -i screen | grep -v grep | awk '{print $1}' `
if [ -z "$radio_proc" ]
then # $radio_proc is empty
if [ ${radio_proc+EMPTY} = EMPTY ]
then file="$file\nradio_proc is empty, but set"
cat $HOME/$active_dir/sc_w3c.log2 > $HOME/$active_dir/sc

Last edited by yigald; 21st April 2009 at 22:18.
yigald is offline   Reply With Quote
Reply
Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump