博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分发上传war包,并且部署至weblogic
阅读量:6327 次
发布时间:2019-06-22

本文共 6141 字,大约阅读时间需要 20 分钟。

系统环境

WebLogic Server Version: 10.3.0.0

OS:linux

分发上传脚本,并且调用远程重新启动weblogic脚本

上代码:

#!/bin/bash##deploy.sh#upload war file to remote serverecho input params: $*remote_name=(server1 server2 server3)declare -A remote_arraydeclare -A war_arrayremote_array=([server1]="10.193.78.31" [server2]="10.193.78.34" [server3]="10.193.78.35")war_array=([server1]="payweb meradmin" [server2]="userCenter merchants payment" [server3]="directLine inmanage")function usage(){  echo "==================================================================================="  echo "Usage:deploy.sh"  echo -e "\t-d : [1 2 3 a] \e[1;31m required.\e[0m desc: exec remote shell cmd for redeploy weblogic "  echo -e "\t\t"  echo -e "\t\t\e[1;31m1 :server1 ; 2: server2 ; 3 :server3 ; a :all server \e[0m"  for i in `eval echo {0..$((${#remote_name[*]}-1))}`  do    echo -e "\t\t${remote_name[i]}:${remote_array["${remote_name[i]}"]}"  done  echo -e "\t\t///"  echo -e "\t-r : \e[1;31m not required.\e[0m desc:remove war file,default is don't remove war file"  echo "**********************************************"  echo -e "example: ./deploy.sh -rd \"1 2 3\""  echo -e "\tdesc: exec server1,server2,server3 shell cmd."  echo "**********************************************"  echo -e "example: ./deploy.sh -rd \"a\""  echo -e "\tdesc: exec all server shell cmd."  echo "**********************************************"  echo -e "example: ./deploy.sh -d \"a\""  echo -e "\tdesc: don\'t remove war file."  echo "**********************************************"  echo "===================================================================================="  exit 1}d="a"r="n"while getopts "d:r" optdo  case $opt in  d)    d=$OPTARG;;  r)    r="y";;  ?)    usage ;;  esacdoneif [ "$d"x = "a"x ];then  d="1 2 3"fiwar_base_dir="/apps/wars/"remote_user="root"remote_war_dir="/apps/besp/"remote_shell_cmd="/root/redeployUAT.sh"#upload war files to remote serverfor i in `eval echo {0..$((${#remote_name[*]}-1))}`do   ip="${remote_array["${remote_name[i]}"]}"   echo "***********************************************************"   echo "start server $ip"   for war in  ${war_array["${remote_name[i]}"]}   do     war_file="$war_base_dir$war.war"     if [ -f "$war_file" ]; then       echo "$war_file is exist,start upload to $ip:$remote_war_dir"       echo scp $war_file $remote_user@$ip:$remote_war_dir       scp $war_file $remote_user@$ip:$remote_war_dir       if [ "$r"x = "y"x ]; then          echo "remove $war_file"          rm -rf $war_file       fi     else       echo $war_file is not exist, skip     fi   done   #exec remote server weblogic shell   if [[ $d =~ $((${i}+1)) ]];then      echo "====================================================================="     echo "exec ssh -t  $remote_user@$ip \"$remote_shell_cmd\""      ssh -t  $remote_user@$ip "$remote_shell_cmd"     echo "====================================================================="   fiecho "end server $ip"echo "***********************************************************"done
#!/bin/sh####redeployUAT.sh  此脚本需要放到31,34,35 各台服务器的/root 目录下,并赋予 可执行权限###重启不同的weblogic 服务dirArray=("userCenter" "merchants" "payment")serverArray=("UserServer" "MerServer" "paymentServer")now=`date "+%Y%m%d%H"`echo current date is $nowweblogicServerBaseDir="/home/weblogic/bea/user_projects/domains/base_domain/servers/"weblogicBinBaseDir="/home/weblogic/bea/user_projects/domains/base_domain/bin/"warBaseDir="/apps/besp/"backupDir="/apps/besp/backup/"#if backupdir not exist create itif [ ! -d "$backupDir" ] ; then  echo "$backupDir"not exist, create it...  mkdir "$backupDir"else    echo "$backupDir"exist, continue...fifor i in "${!dirArray[@]}"; do    #printf "%s\t%s\n" "$i" "${dirArray[$i]}"    #start for loop    cd $warBaseDir    dir="${dirArray[$i]}"    server="${serverArray[$i]}"       #tar directory    tar -zcf "$backupDir/$dir$now".tar.gz $dir    #delete directory    echo delete directory $dir...    rm -rf $dir    #unzip new package    #unzip -o $dir.war -d $dir -p    unzip -q -o -d $dir $dir.war    echo kill $server process...    kill -9 `ps -ef|grep $server |grep -v grep|awk '{print $2}'`    #change work diretory to weblogic servers    echo change dir to "$weblogicServerBaseDir$server"    cd "$weblogicServerBaseDir$server"    echo remove "$server" cache    rm -rf logs    rm -rf tmp    rm -rf cache    rm -rf stage    echo change dir to "$weblogicBinBaseDir"    cd $weblogicBinBaseDir    rm -rf $dir.out    sleep 2s    if [ "x"`ps -ef|grep $server |grep -v grep|awk '{print $2}'` == "x" ]; then        echo "$server has been stoped successfully."            echo start weblogic "$server"            # AdminServer use startWebLogic.sh            #otherServer usr startManagedWebLogic.sh            if [  "x$server" == "xAdminServer" ];then              nohup ./startWebLogic.sh > $dir.out 2>&1 &            else              nohup ./startManagedWebLogic.sh $server> $dir.out 2>&1 &            fi            while true            do              result=`cat $weblogicBinBaseDir$dir.out |grep "RUNNING mode"`              result="${result:0-14:7}"              if [[ "$result"x == "RUNNING"x ]]; then                  echo -e "\n\033[32;40;7mstart weblogic $server success..\033[0m\n"                  break              else                 sleep 1s                 result=`cat $weblogicBinBaseDir$dir.out |grep FORCE_SHUTTING_DOWN`                 result="${result:0-20:19}"                 if [[ "$result"x == "FORCE_SHUTTING_DOWN"x ]]; then                    echo -e "\033[31;43;7mweblogic $server start failed. please check $dir.out.\033[0m"                    break;                 fi                 echo -e ".\c"                 continue              fi            done            echo ""            #tail -f $dir.out    else       echo "$server stop failed retry"       kill -9 `ps -ef|grep $server |grep -v grep|awk '{print $2}'`       sleep 2s    fi    #end for loopdoneecho -e "\n\033[32;40;7mAll server start end.Please check the weblogic console.\033[0m"

代码已经上传至oschina git ,地址:https://git.oschina.net/ly1022/linuxShellDeployScript.git

转载于:https://www.cnblogs.com/wolfmoon/p/5216914.html

你可能感兴趣的文章
C# ArcEngine 实现点击要素高亮并弹出其属性
查看>>
初识GO语言——安装Go语言
查看>>
SDK命令行操作
查看>>
基于Bootstrap的DropDownList的JQuery组件的完善版
查看>>
EXTJS学习系列提高篇:第二十四篇(转载)作者殷良胜,ext2.2打造全新功能grid系列--阅增删改篇...
查看>>
Hadoop MapReduce编程 API入门系列之分区和合并(十四)
查看>>
判断二叉树是否平衡、是否完全二叉树、是否二叉排序树
查看>>
并查集的应用之求解无向图中的连接分量个数
查看>>
7个神奇的jQuery 3D插件
查看>>
在线浏览PDF之PDF.JS (附demo)
查看>>
波形捕捉:(3)"捕捉设备"性能
查看>>
AliOS Things lorawanapp应用介绍
查看>>
美国人的网站推广方式千奇百怪
查看>>
java web学习-1
查看>>
用maven+springMVC创建一个项目
查看>>
linux设备驱动第四篇:以oops信息定位代码行为例谈驱动调试方法
查看>>
redis知识点整理
查看>>
Hello World
查看>>
Spring3全注解配置
查看>>
ThreadLocal真会内存泄露?
查看>>