#!/bin/sh # ice-downcoder-loop.sh --- runs ice-downcoder, restarting it if it dies. # If the net is down, waits for it to come back up before restarting. # Copyright © 2000-2004 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation. No representations are made about the suitability of this # software for any purpose. It is provided "as is" without express or # implied warranty. # # Created: 30-Jun-2000. PATH=/usr/local/bin:$PATH PATH=/home/jwz/src/icecast:$PATH export PATH LD_LIBRARY_PATH=/usr/local/lib export LD_LIBRARY_PATH progname="ice-downcoder" prog="ice-downcoder.pl" host=axon.dnalounge.com delay=1 soundp=false pingable() { if ( ping -q -n -c 2 $host >/dev/null ); then return 0 else return 1 fi } run_once() { $prog "$@" if ! pingable $host ; then echo "$host unpingable! waiting..." while ! pingable $host; do sleep $delay done echo "$host pingable again." else echo "restarting in $delay seconds" >&2 sleep $delay killall lame arecord >/dev/null 2>&1 sleep 1 killall -9 lame arecord >/dev/null 2>&1 if [ "$soundp" = true ]; then # Fuck! reload the ALSA kernel modules just in case. # alsa-kernel-reset.pl true # modprobe snd-emu10k1 fi if [ -d /dev/snd ]; then if [ "`find /dev/snd/* \! -perm -066 2>/dev/null`" != "" ]; then echo '/dev/snd/* permissions wrong!' >&2 sleep 30 fi fi fi } run_loop() { if ( echo " $@ " | grep soundcard >/dev/null ); then soundp=true fi while true ; do run_once "$@" done } # log all stdout/stderr text to syslog log_lines() { while read line ; do line=`echo "$line" | sed "s/^$progname: //"` logger -st "$progname" "$line" done } #echo "started at `date`" | log_lines run_loop "$@" 2>&1 | log_lines exit 0