#!/bin/bash
exec 2>&1
export TERM=linux
. /etc/rc.conf
. /etc/rc.d/functions
stat_runit "Starting Ceton bridge"
pid_string=''

for i in `ls /etc/ceton_proxy.d/|sort -r`
do
    . /etc/ceton_proxy.d/$i
    #forcing foreground and then running with & is to capture the pid
    balance -f $port $ip:80  >/dev/null &
    stat_runit "    proxy $ip on port $port"
    pid=$!
    pid_string="$pid_string $pid"
done

if [ "x$pid_string" = "x" ]
then
    sv stop cetonproxy
else
    wait $pid_string
fi

