fastjson在线升级到1.2.61

笔者在内部构建轻量级监控平台的时候出现了fastjson的问题,需要再次升级,因此笔者先构建了一个shell脚本,用于全量替换fastjson低版本然后重启。
shell脚本如下:

#!/bin/bash
#fastjson升级脚本
#功能需求: 通过脚本一键升级web服务的低版本fastjson并重启
 
cd /opt/shell
if [ ! -d "/opt/shell/fastjson" ];then
   mkdir /opt/shell/fastjson
   cd /opt/shell/fastjson
   curl https://lightmonitorapi.test.cn/pull/fastjson1261 -o fastjson-1.2.61.jar
else
   cd /opt/shell/fastjson
   curl https://lightmonitorapi.test.cn/pull/fastjson1261 -o fastjson-1.2.61.jar
fi
 
 
cd /opt/web
for s in $(ls)
do
  fastjson=$(find /opt/web"/"$s -name fastjson*.*)
  if [ -n "$fastjson" ];then
     jsonresult=$(echo "$fastjson"| grep "1.2.61")
     if [ ! -n "$jsonresult" ];then
        fileName=$(echo "$fastjson" | awk -F'/' '{print $4}')
        service=$(ps -ef | grep -v "grep" | grep "$fileName")
        if [ -n "$service" ];then
           echo "service="$fileName" is running."
           cp /opt/shell/fastjson/fastjson-1.2.61.jar   "/opt/web/"$fileName"/webapps/WEB-INF/lib/fastjson-1.2.61.jar"
           mv "$fastjson" $fastjson"backup"
           sh "/opt/web/"$fileName"/restart.sh"
           echo "service="$fileName" is running ,fastjson upt to 1.2.61, restart success."
           sleep 5
        else
           cp /opt/shell/fastjson/fastjson-1.2.61.jar   "/opt/web/"$fileName"/webapps/WEB-INF/lib/fastjson-1.2.61.jar"
           mv "$fastjson" $fastjson"backup"
           echo "service="$fileName" is not running fastjson up to 1.2.61."
        fi
     fi
  fi
 
done

本文由博客一文多发平台 OpenWrite 发布!

你可能感兴趣的:(shell)