function ack()
{
    ack_phrase="$1"
    log_path="$2"
    max_wait_log_generate_time="$3"
    max_wait_ack_time="$4"
    wait_log_generate_time=0
    wait_ack_time=0
    echo "begin acknowledge whether the deploy start OK, ACK_PHRASE=${ack_phrase}, log_path=${log_path}"
    while [ ! -f ${log_path} ]
    do
        echo "wait_log_generate_time is ${wait_log_generate_time}, max_wait_log_generate_time is ${max_wait_log_generate_time} "
        if ((${wait_log_generate_time}>${max_wait_log_generate_time}))
        then
            echo "the log generated time exceed the limit"
            exit -1
        fi
        echo 'the log does not exist, wait for 3 seconds'
        sleep 3
        let "wait_log_generate_time+=3"
    done
    echo "listen for the log ack..."
    for ((i=0;;))
    do
        bootstrap_flag=`cat ${log_path} |grep "${ack_phrase}"| wc -l`
        if [ "${bootstrap_flag}" = 0 ] && [ "${max_wait_ack_time}" -gt "${wait_ack_time}" ]
        then
            sleep 3
            let "wait_ack_time+=3"
            echo "waiting for bootstrap flag for ${wait_ack_time}"
        elif [ "${bootstrap_flag}" = 1 ]
        then
            echo "server is start~"
            exit 0
        else
            echo "server not startup in ${max_wait_ack_time} seconds..."
            exit -1
        fi
    done
}



P_UUID=`ps -ef|grep atm-crypter |grep -v 'grep'|awk '{print $2}'`
echo $P_UUID
if [ -n "${P_UUID}" ];then
	echo "-----KILL acsatm PPID=${P_UUID}"
	kill -9 ${P_UUID}
	sleep 1s
fi
timestamp_log=`date +%Y-%m-%d.%H%M%S`
mv /home/deploy/atm_arms/acs/logs/acs.log /home/deploy/atm_arms/acs/logs/acs.log.$timestamp_log
echo "java -jar /home/deploy/atm_arms/acs/atm-crypter-service-1.0-SNAPSHOT.jar > /dev/null 2>&1 &"
cd /home/deploy/atm_arms/acs/
java -jar /home/deploy/atm_arms/acs/atm-crypter-service-1.0-SNAPSHOT.jar > /dev/null 2>&1 &
ack "Started Application" /home/deploy/atm_arms/acs/logs/acs.log 50 500
