improve script to be more patient but exit after there stop being

messages -- which usually means the games finished.  With this and
previous changes the background stuff works most of the time.  Now to
debug why it's not all of the time.
This commit is contained in:
Andy2 2011-09-30 18:22:25 -07:00
parent dee826c6b1
commit 38adeb9160

View file

@ -4,7 +4,9 @@
set -e -u set -e -u
PID=$$ PID=$$
echo "**********************************************************************"
echo "pid: $PID" echo "pid: $PID"
echo "**********************************************************************"
ROOM=ROOM_$PID ROOM=ROOM_$PID
DIR=$(basename $0)_$PID DIR=$(basename $0)_$PID
@ -27,28 +29,31 @@ done
# run apps until done # run apps until done
NBS=$DIR/nbs NBS=$DIR/nbs
while :; do ZERO_COUNT=0
while [ $ZERO_COUNT -lt 5 ]; do
WORK_DONE=""
for NUM in $(seq 1 2); do for NUM in $(seq 1 2); do
echo "running for $NUM"
LOG=$DIR/game_${NUM}.log LOG=$DIR/game_${NUM}.log
RELAYID=$(./scripts/relayID.sh --short $LOG) RELAYID=$(./scripts/relayID.sh --short $LOG)
MSG_COUNT=$(../relay/rq -m $RELAYID 2>/dev/null | sed 's,^.*-- ,,') MSG_COUNT=$(../relay/rq -m $RELAYID 2>/dev/null | sed 's,^.*-- ,,')
if [ "$MSG_COUNT" -gt 0 ]; then if [ "$MSG_COUNT" -gt 0 ]; then
echo "calling $APP" WORK_DONE=true
$APP $COMMON_ARGS --file $DIR/game_${NUM}.xwg \ $APP $COMMON_ARGS --file $DIR/game_${NUM}.xwg \
--with-nbs $NBS > /dev/null & --with-nbs $NBS > /dev/null &
PID1=$! PID1=$!
sleep 1 # let server get ready sleep 1 # let server get ready
echo "calling rq"
../relay/rq -f $RELAYID -b $NBS ../relay/rq -f $RELAYID -b $NBS
sleep 2 sleep 2
kill $PID1 && wait $PID1 || true kill $PID1 && wait $PID1 || true
else else
echo "$MSG_COUNT messages for $RELAYID" sleep 1
fi fi
done done
[ -z "$WORK_DONE" ] && ZERO_COUNT=$((ZERO_COUNT+1))
done done
echo "$0 done (pid: $PID)" echo "$0 done (pid: $PID)"