提交 b53923b6 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

only select one newest record for excel update

上级 6ecaa0e5
*/1 * * * * ./check_service.sh zd 8849 >> check_service.log
\ No newline at end of file
#!/usr/bin/env bash
dftPortZtf=8848
dftPortZd=8849
interval=7
nowTime=`date +"%Y-%m-%d %H:%M:%S"`
nowDate=`date +"%Y-%m-%d"`
PARAM_NAME=$1
PARAM_PORT=$2
if [ -z "$PARAM_NAME" ]; then
echo "first parameter - name can't be empty"
exit 1
fi
DIR="$( cd "$( dirname "$0" )" && pwd )"
PORT=`ps -ef | grep "$PARAM_NAME" | grep -v "grep" | grep -v ".sh" | awk '{print $10}'`
echo name: $PARAM_NAME, dir: $DIR, port $PORT
# init $PARAM_PORT
if [ -z "$PARAM_PORT" ]; then
if [ -z "$PORT" ]; then
if [ "$PARAM_NAME" = "ztf" ]; then
PARAM_PORT="$dftPortZtf"
else
PARAM_PORT="$dftPortZd"
fi
else
PARAM_PORT="$PORT"
fi
fi
# just upgraded
if [ -f "$DIR/.upgraded"]; then
echo upgraded, force to restart.
PORT="-1" # different port cause service be killed and restart
fi
for var in 1 2
do
if [ -z "$PORT" ]; then # empty, start service
echo $nowTime start service on port $PARAM_PORT in dir $DIR.
cd $DIR
nohup ./ztf -P $PARAM_PORT > nohup.log 2&>zenops-agent-$nowDate.log &
rm -f "$DIR/.upgraded"
echo ""
break
else
if [ $PORT = $PARAM_PORT ]; then # do nothing
echo service is still alive
echo sleep $interval second the $var time.
sleep $interval
else # kill current service
echo kill service on port $PORT.
ps -ef | grep "$PARAM_NAME" | grep -v "grep" | grep -v ".sh" | awk '{print $2}' | xargs kill -9
PORT="" # cause service started in the next iteration
fi
fi
done
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册