标签:init ppa war mpi 日志文件 ble ora host xms
注意:本脚本用于Shell脚本分享,因环境不同,不可直接用于其它环境部署用。#!/bin/bash
#时间:2019年7月29日
#作者:肖山
#微信:helpxiaoshan
#用途:用于XXXX UAT环境ATG商城项目Jenkins自动部署使用。
############ 使用注意事项:#################################################################################
############################################################################################################
starttime=date +‘%Y-%m-%d %H:%M:%S‘
project_name=$1 #第一个参数为项目名
[ $1 ] || echo "ERROR: No project_name!" #判断$1为空,则退出脚本呢!
[ $1 ] || exit 1
if [ $project_name = "store" ];then
#第一步,停掉目标项目进程。
ip=192.168.220.34
echo "INFO: project_name is store"
echo -e "\n"
echo "INFO: Begain stop store..."
ssh -n -l oracle $ip "pgrep -f -l store | grep -v ‘tail -f‘ | grep -v grep | cut -d‘ ‘ -f1 | xargs kill -9" >>/dev/null 2>&1
stat=$?
#echo $stat
[ $stat -eq 0 ] && echo "INFO: store is been killed"
[ $stat -ne 0 ] && echo "INFO: store is not started"
#第二步,删除旧代码并清除缓存。
echo -e "\n"
echo "INFO: Begain delete old file and cache..."
ssh -n -l oracle $ip "rm -rf /home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/prod_lockserver/stage/prod_lockserver.ear/prod_lockserver.ear"
ssh -n -l oracle $ip "rm -rf /home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/prod_lockserver/tmp"
ssh -n -l oracle $ip "rm -rf /home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/prod_lockserver/cache"
echo "INFO: already delete old file and cache"
#第三步,拷贝最新代码到项目路径下。
echo -e "\n"
echo "INFO: Begain copy code to project host..."
scp -qrp /file/uat_ears/prod_lockserver.ear oracle@$ip:/home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/prod_lockserver/stage/prod_lockserver.ear
[ $stat -eq 0 ] && echo "INFO: copy Success"
[ $stat -ne 0 ] && echo "ERROR: copy failed!!!" && exit 1
#第四步,启动项目进程
echo -e "\n"
echo "INFO: Begain start store Weblogic"
ssh -n -l oracle $ip "nohup /home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/bin/startManagedWebLogic.sh prod_lockserver http://192.168.220.35:7001 -Djava.rmi.server.hostname=192.168.220.34 -Dguangda.merchant.parameter.file.path=/file/cebbank/ceb_merchant.properties -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8466,server=y,suspend=n -Djava.compiler=NONE -Datg.dynamo.server.name=prod_lockserver -Xms6G -Xmx6G -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseG1GC -XX:MaxGCPauseMillis=1000 -XX:InitiatingHeapOccupancyPercent=45 -XX:ConcGCThreads=4 -XX:G1ReservePercent=15 -XX:+DisableExplicitGC -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+PrintGCCause -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:+PrintGCApplicationStoppedTime -Xloggc:/home/oracle/store_gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/oracle/store_heap.bin -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=192.168.220.34 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Datg.dynamo.data-dir=/home/oracle/ATG-Data/ > /home/oracle/output/logs/prod_lockserver.log &"
echo "INFO: Weblogic starting..."
#第五步,启动精确检测weblogic启动完毕的后台进程
echo -e "\n"
>${project_name}_${ip}_status.log #清空检测Weblogic是否启动的日志文件内容
for i in `seq 20` #启动10个检测Weblogic启动日志后台进程,当后台进程被杀掉后,日志才会被写入log文件
do
ssh -n -l oracle $ip "tail -fn 0 /home/oracle/output/logs/prod_lockserver.log" | grep "The server started in RUNNING mode" >>${project_name}_${ip}_status.log &
done
#检测Weblogic启动状态的变量stats1,检测机制为检测目标服务器上的项目日志文件,是否新打印出"The server started in RUNNING mode";
t=0
stats1=0
while [ $stats1 -eq 0 ]
do
sleep 15 # 10个后台进程,20x15=300s,检测时间共300秒,当有项目的tomcat启动时间超过100秒,则增大该数值。
let t+=15 #t=`expr $t + 10`
echo "检测 $project_name Weblogic 是否启动完毕,已用时 $t 秒..."
echo -e "\n"
ssh -n -l oracle $ip "pgrep -f ‘tail -fn‘ | head -n 1 | xargs kill -9" # kill掉一个后台进程
[ $? -eq 0 ] && echo "INFO: 成功杀掉 tail -fn 后台进程。"
stats1=`cat ${project_name}_${ip}_status.log | wc -l ` # 每kill一个后台进程,状态文件就更新一次
#[ $stats1 -eq 0 ] && echo "INFO:未检测到 started in RUNNING mode 关键词。"
#[ $stats1 -ge 1 ] && echo "INFO:成功检测到 started in RUNNING mode 关键词。"
done
ssh -n -l oracle $ip "pgrep -f ‘tail -fn‘ | xargs kill -9" # kill掉剩余无用后台进程。
echo -e "\n"
echo "INFO:检测到启动关键词:"
head -n 1 ${project_name}_${ip}_status.log # 输出抓取的 started in RUNNING mode 日志。
echo -e "\n"
echo "打印最后864行日志"
ssh -n -l oracle $ip "tail -n 864 /home/oracle/output/logs/prod_lockserver.log"
fi
#计算脚本运行总时间
endtime=date +‘%Y-%m-%d %H:%M:%S‘
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次更新用时: "$((end_seconds-start_seconds))"s"
标签:init ppa war mpi 日志文件 ble ora host xms
原文地址:https://blog.51cto.com/helpxiaoshan/2424619