系统环境
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