[icecast] Keepalive/last 10 songs list

matthew at epiphanycorp.com matthew at epiphanycorp.com
Sun Dec 16 06:25:39 UTC 2001



Thanks to Robin and William for their keepalive scripting fu. Icecast/IceS are very crashy, and this script has worked pretty flawlessly for me. I also added some stuff to build a list of the last ten songs played. 

I'm using the version of the script that checks in the stats.log file for the source every two minutes. While it's doing that, it also figures out the currently playing song, and adds it to a list of the last ten songs played, a text file called 'songs.log.' I use PHP to parse this text file into a Web page for my site.

There's probably a much better way to do this, but it seems to work pretty well for me.

Thanks again, y'all.

Matthew

#!/bin/sh
# keepalive script for Icecast server and IceS source
# Also updates 'songs.log' file with ten last songs played

DIR=/usr/local/icecast
LOG=$DIR/logs/ka.log

echo "`date` -- Keepalive started for EpiphanyRadio" >> $LOG
while [ 0 ]
do
# Make sure the server itself is up -- if it's not running, restart the server and the source
SERVER=`ps ax | grep -c "$DIR/bin/icecast"`
if [ "$SERVER" -eq 1 ] ; then
        $DIR/bin/icecast -c $DIR/conf/icecast.conf >/dev/null 2>/dev/null &
        echo "Icecast crash -- Icecast restarted on `date`." >> $LOG
        $DIR/bin/ices -c $DIR/conf/ices.conf >/dev/null 2>/dev/null &
        echo "IceS restarted on `date`." >> $LOG
        # Sleep for five minutes to allow logs to begin being written
        sleep 300
# Otherwise, make sure the source is connected -- if it's not, kill the server, then restart the server and the source
else
        SOURCE=`cat $DIR/logs/stats.log | grep Source\ [0-1] | awk '{print $1" "$2}'| sort | uniq`
        PIDS=`ps ax | grep "$DIR/bin/ice\(cast\|s\)\?" | awk '{print $1}'`
        if [ "$SOURCE" ] ; then
        
                # Update songs.log with last ten songs played
                CURRENT=`awk 'BEGIN { RS = "" ; FS = "\n" }{print substr($7, 16, (length($7)-16))}' $DIR/logs/stats.log`
                EXISTS=`cat $DIR/logs/songs.log | grep "$CURRENT"`
                if [ ! "$EXISTS" ] ; then
                        echo $CURRENT > $DIR/logs/songs.log.tmp
                        awk 'BEGIN { RS = "" ; FS = "\n" }{ 
                                print $1
                                print $2
                                print $3
                                print $4
                                print $5
                                print $6
                                print $7
                                print $8
                                print $9
                                }' $DIR/logs/songs.log >> $DIR/logs/songs.log.tmp
                        mv $DIR/logs/songs.log.tmp $DIR/logs/songs.log
                fi
        else
                if [ "$PIDS" ] ; then
                        echo "Killing rogue processes..." >> $LOG
                        echo "PID(s): $PIDS" >> $LOG
                        kill -9 $PIDS >/dev/null 2>/dev/null &
                        $DIR/bin/icecast -c $DIR/conf/icecast.conf >/dev/null 2>/dev/null &
                        echo "Icecast restarted on `date`." >> $LOG
                        $DIR/bin/ices -c $DIR/conf/ices.conf >/dev/null 2>/dev/null &
                        echo "IceS restarted on `date`." >> $LOG
                else
                $DIR/bin/icecast -c $DIR/conf/icecast.conf >/dev/null 2>/dev/null &
                echo "Icecast restarted on `date`." >> $LOG
                $DIR/bin/ices -c $DIR/conf/ices.conf >/dev/null 2>/dev/null &
                echo "IceS restarted on `date`." >> $LOG
                fi
                # Sleep for five minutes to allow logs to begin being written
                sleep 300
        fi
fi
sleep 120
done

--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast mailing list