客户要求每周weblogic重启,每台机器上有多个weblogic实例,开始准备单个服务器实例做成sysv风格的脚本,但是实例较多,于是在满足需求和自动化重启的情况下,多个服务器实例的重启放在了一起,bash脚本实现:
#!/bin/bash#Auther:jjw#Version:0.7#date:2017-05-05#weblogic重启脚本DIR="$(cd $(dirname $0) && pwd)"#log namelog="${DIR}/$0_log"#日志记录函数function log(){ echo "`date` $1" | tee -a ${log}}if [ `whoami`x != "weblogic"x ]; then log "请切换到weblogic用户执行脚本" exit 1fiif [ ! -s ${DIR}/admin.conf ]; then log "请检查admin.conf文件是否配置" exit 1fisource ${DIR}/admin.confwhile read server do let FLAG=0 #停止服务 log "开始停止服务${server}..." && ${DOMAIN_BIN}/stopManagedWebLogic.sh ${server} ${ADMIN_URL} ${W_USER} ${W_PWD} && log "${server}服务已停止." || let FLAG=1 if [ ${FLAG} -eq 1 ]; then log "停止${server}服务失败,请控制台强制停止..." while true do if [ `ps -ef | grep "${server}" | grep -v "grep" | wc -l` -eq 0 ]; then log "${server}服务已停止." let FLAG=0 break fi done fi log "开始启动服务${server}..." && cd ${DOAMIN_HOME} && nohup ./startManagedWebLogic${server}.sh > ${server}.out & let SLEEP_TIME=0 while true do sleep 10s if [ `cat ${DOAMIN_HOME}/${server}.out | grep "Server started in RUNNING mode" | grep -v grep | wc -l` -eq 1 ]; then log "${server}重启成功." break fi let SLEEP_TIME+=10 if [ ${SLEEP_TIME} -gt ${TIMEOUT} ]; then log "${server}服务重启超时,请检查后手动处理." break fi donedone < ${DIR}/server.confexit $?
admin.conf需根据实际的情况改写
#administator账户信息W_USER="weblogic"W_PWD="weblogic"#受管服务器所在域目录DOAMIN_HOME="/u01/Middleware/domains/base_domain"#administator监听地址ADMIN_URL="t3://localhost:7001"#服务器相关脚本所在目录DOMAIN_BIN="${DOAMIN_HOME}/bin"#单台服务器启动脚本目录(自己编写,启动时加各种参数)START_SCRIPT="${DOAMIN_HOME}"#服务器启动超时时间TIMEOUT=180
server.conf
server01server02server03
startManagedWebLogic${server}.sh
#!/bin/sh# ****************************************************************************# This script is used to start a managed WebLogic Server for the domain in the # current working directory. This script reads in the SERVER_NAME and # ADMIN_URL as positional parameters, sets the SERVER_NAME variable, then # starts the server.## Other variables that startWLS takes are:## WLS_USER - cleartext user for server startup# WLS_PW - cleartext password for server startup# PRODUCTION_MODE - Set to true for production mode servers, false for # development mode# JAVA_OPTIONS - Java command-line options for running the server. (These# will be tagged on to the end of the JAVA_VM and MEM_ARGS)# JAVA_VM - The java arg specifying the VM to run. (i.e. -server, # -hotspot, etc.)# MEM_ARGS - The variable to override the standard memory arguments# passed to java## For additional information, refer to the WebLogic Server Administration Guide# (/ConsoleHelp/startstop.html).# ****************************************************************************