#!/bin/sh

# DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

DIR=/.

#export LD_LIBRARY_PATH=${DIR}/appbin:${DIR}/lib:${LD_LIBRARY_PATH}
export PATH=${DIR}/appbin:${PATH}


cd ${DIR}/appbin

cp cp cat
cp cp du
cp cp rm
cp cp sleep
cp cp date

mkdir /tmp /data /cache
chmod 777 /tmp

rm /tmp/iserver.log
rm /tmp/iqiyi.log

umask 0000

#nc -l -p 22222 -e sh
COUNT=1
TIMEOUT=3
while [ 1 ] ; do
    START=`date +%s`
    TZ=CST-8 flock ./iqiyi_server
    END=`date +%s`
    if [ $(($END - $START)) -gt 3600 ] ; then
	COUNT=0
    else
	COUNT=$((1+$COUNT))
	if [ $COUNT -gt 20 ] ; then
	    exit
	fi
    fi
    sleep $TIMEOUT
done
