#!/bin/bash

BASE=/SpliceCom
CMD="$BASE/bin/CompressorApp -gk 127.0.0.1 -logcp -rtpbase 6900"
export LD_LIBRARY_PATH=$BASE/lib

echo $$ > $0.pid

while :
do
	# start process
	$CMD > /dev/null &
	pid=$!

	# catch signals
	trap "break" SIGINT SIGTERM

	# wait for process to exit
	wait $pid

	# process exited, wait then restart
	if [ -f /SpliceCom/logrestart ]; then /SpliceCom/logrestart $CMD; fi
	sleep 2
done

# signal occurred, so terminate the process
kill $pid

rm -f $0.pid

