#!/bin/bash 
#
source /etc/profile
export PATH=${PATH}:/xyapp/system/miner.plugin-dockerd.ipk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#
APPID=2698d6c20affd188754ca34f17f43918
num=$(docker ps | grep $APPID | wc -l)
if [ "$num" -gt 1 ];then
    #new_num=$(echo $num|awk '{print int($1/2)}')
    new_num=20
else
    exit 1
fi
#

which jq &> /dev/null || yum install jq -y

#
if [ -f /etc/xyapp/biz_conf.json ];then
    if [ $(cat /etc/xyapp/biz_conf.json |grep $APPID |wc -l) -ge 0 ];then
        /usr/bin/jq ".\"2698d6c20affd188754ca34f17f43918\".instance_count=${new_num}" /etc/xyapp/biz_conf.json > /root/tmp.json && mv -f  /root/tmp.json /etc/xyapp/biz_conf.json
    else
       /usr/bin/jq --arg k "$APPID" --argjson v "{\"instance_count\": ${new_num}}" '.[$k]=$v' /etc/xyapp/biz_conf.json > /root/tmp.json && mv -f  /root/tmp.json /etc/xyapp/biz_conf.json
    fi
else
    echo "{\"2698d6c20affd188754ca34f17f43918\":{\"instance_count\": ${new_num}}}"  > /etc/xyapp/biz_conf.json
fi
sleep 60
/xyapp/system/miner.plugin-agent.ipk/stop.sh;sleep 1; /xyapp/system/miner.plugin-agent.ipk/start.sh
sleep 600
/xyapp/system/miner.plugin-agent.ipk/stop.sh;sleep 1; /xyapp/system/miner.plugin-agent.ipk/start.sh
