1 #!/bin/bash 2 #sh xx.sh start xx项目 例如:sh autoWeblogic.sh start bius 3 #经测试发现weblogic 启动大概需要完全启动成功35秒左右 停止大概需要1~7秒 4 #如果多个项目可以把DOMAIN_NAME换成动态的参数进行传递 5 ### BEGIN WLS Configration 6 DOMAIN_NAME=appadmin 7 SERVER_NAME=$2 8 #得到服务器的ip 9 IP=`ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | awk -F: '{print $2}'` 10 ADMIN_URL="t3://ip:8001" 11 DOMAIN_PATH=/Oracle/Middleware/user_projects/domains/${DOMAIN_NAME} 12 #使用这个命令得到weblogic对应服务进程的进程号 (grep -w ${SERVER_NAME}) 可以精确匹配 13 #WLS_PID=`ps -ef|grep java|grep =${SERVER_NAME}|awk '{print $2}'` 14 WLS_PID=`ps -ef|grep java|grep -w ${SERVER_NAME}|awk '{print $2}'` 15 #USER_NAME=`logname` 16 USER_NAME=`whoami` 17 ## WLS_MEMORY 18 USER_MEM_ARGS="-Xms2048m -Xmx3096m -XX:PermSize=256m -XX:MaxPermSize=512m" 19 export USER_MEM_ARGS 20 ### END WLS Configration 21 22 ######### Weblogic server start|stop|restart|status 23 #用于等待进程启停 24 wait_for_pid () 25 { 26 try=0 27 case "$1" in 28 'created') 29 while test $try -lt 35 ; do 30 printf . 31 try=`expr $try + 1` 32 sleep 1 33 done 34 WLS_PID=`ps -ef|grep java|grep -w ${SERVER_NAME}|awk '{print $2}'` 35 if [ "$WLS_PID" != "" ] ; then 36 try='' 37 fi 38 ;; 39 'removed') 40 while test $try -lt 7 ; do 41 WLS_PID=`ps -ef|grep java|grep -w ${SERVER_NAME}|awk '{print $2}'` 42 if [ "${WLS_PID}" = "" ] ; then 43 try='' 44 break 45 fi 46 printf . 47 try=`expr $try + 1` 48 sleep 1 49 done 50 ;; 51 esac 52 } 53 #判断操作用户名,不能是root需要使用weblogic用户 54 if [ "$USER_NAME" = "root" ] ; then 55 echo "USER_NAME is $USER_NAME! Plz use weblogic!" 56 exit 1 57 fi 58 #domain不能为空 59 if [ "$DOMAIN_NAME" = "" ] ; then 60 echo "DOMAIN_NAME is not set! Plz set DOMAIN_NAME!" 61 exit 1 62 fi 63 #service不能为空 64 if [ "$SERVER_NAME" = "" ] ; then 65 echo "SERVER_NAME is not set! Plz set SERVER_NAME!" 66 exit 1 67 fi 68 #url不能为空 69 if [ "$ADMIN_URL" = "" ] ; then 70 echo "ADMIN_URL is not set! Using default ADMIN_URL!" 71 fi 72 #如果是查看状态命令 73 if [ "$1" = "status" ] 74 then 75 if [ "${WLS_PID}" = "" ] ; then 76 echo "No pid - $SERVER_NAME is not running !" 77 exit 1 78 else 79 echo "$SERVER_NAME is running !" 80 exit 0 81 fi 82 fi 83 84 #如果是停止命令 85 if [ "$1" = "stop" ] 86 then 87 printf "Terminating $SERVER_NAME " 88 if [ "${WLS_PID}" = "" ] ; then 89 echo "No pid - $SERVER_NAME is not running !" 90 else 91 kill -9 $WLS_PID 92 wait_for_pid removed 93 if [ -n "$try" ] ; then 94 echo " failed " 95 exit 1 96 fi 97 echo " done ! " 98 exit 0 99 fi100 else101 #启动命令102 printf "Starting $SERVER_NAME "103 if [ "${WLS_PID}" = "" ] ; then104 nohup sh $DOMAIN_PATH/bin/startWebLogic.sh &105 else 106 kill -9 $WLS_PID107 wait_for_pid removed108 if [ -n "$try" ] ; then109 echo "restart failed "110 exit 1 111 fi112 nohup sh $DOMAIN_PATH/bin/startWebLogic.sh &113 fi114 #if echo $SERVER_NAME|grep -q dmin ; then 115 # nohup sh $DOMAIN_PATH/bin/startWebLogic.sh &116 # else 117 # nohup sh $DOMAIN_PATH/bin/startManagedWebLogic.sh $SERVER_NAME $ADMIN_URL &118 # fi 119 wait_for_pid created120 if [ -n "$try" ] ; then121 echo " failed "122 exit 1123 else124 echo " done ! "125 exit 0126 fi 127 fi128 echo "To check the log, you may excute:"129 echo "tail -100f "