#! /bin/sh
#
# re_jackmixer init.d script
# run re_restream and jackd from this script

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

set -e
LOGFILE="/var/log/streamswitch.log"

STREAMSWITCH=`/etc/reboot.fm/re_codec_read_config streamswitch`

case "$1" in
  start)
  	case $STREAMSWITCH in
              enabled)
		echo -n "Starting re_codec: streamswitch"
		streamswitch.py > $LOGFILE &
		echo "."
		;;
	       *)
		echo -n "Starting re_codec: streamswitch disabled."
		exit 0·
		;;
	esac
	;;
  stop)
	echo -n "Stopping re_codec: streamswitch"
	kill `ps ax  | awk '/python\ .*streamswitch.py/ {print $1}'`
	echo "."
	;;
  restart|force-reload)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
