1. 程式人生 > >shell指令碼監控啟動停止weblogic服務

shell指令碼監控啟動停止weblogic服務

有時,linux系統需要做HA或者類似的功能,需要配置weblogic指令碼來啟動,停止,檢視狀態,可以如下方式寫

命令形式:Weblogic server start|stop|restart|status

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

### BEGIN WLS Configration

DOMAIN_NAME=base_domain

SERVER_NAME=AServer

DOMAIN_PATH=/Oracle/Middleware/user_projects/domains/${DOMAIN_NAME}

#使用這個命令得到weblogic對應服務程序的程序號

WLS_PID=`ps -ef|grep java|grep =${SERVER_NAME}|awk '{print $2}'`

#USER_NAME=`logname`

USER_NAME=`whoami`

## WLS_MEMORY

USER_MEM_ARGS="-Xms2048m -Xmx3096m -XX:PermSize=256m -XX:MaxPermSize=512m"

export USER_MEM_ARGS

### END WLS Configration

######### Weblogic server start|stop|restart|status

#用於等待程序啟停

wait_for_pid ()

{

try=0

case "$1" in

'created')

while test $try -lt 7 ; do

printf .

try=`expr $try + 1`

sleep 1

done           

WLS_PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2}'`           

if [ "$WLS_PID" != "" ] ; then

try=''                        

fi

;;

'removed')

while test $try -lt 35 ; do 

WLS_PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2}'`

if [ "${WLS_PID}" = "" ] ; then

try=''

break

fi

printf .

try=`expr $try + 1`

sleep 1

done

;;

esac

}

#判斷操作使用者名稱,不能是root需要使用weblogic使用者

if [ "$USER_NAME" = "root" ] ; then

echo "USER_NAME is $USER_NAME! Plz use weblogic!"

exit 1

fi

#domain不能為空

if [ "$DOMAIN_NAME" = "" ] ; then

echo "DOMAIN_NAME is not set! Plz set DOMAIN_NAME!"

exit 1

fi

#service不能為空

if [ "$SERVER_NAME" = "" ] ; then

echo "SERVER_NAME is not set! Plz set SERVER_NAME!"

exit 1

fi

#url不能為空

if [ "$ADMIN_URL" = "" ] ; then

echo "ADMIN_URL is not set! Using default ADMIN_URL!"

fi

#如果是檢視狀態命令      

if [ "$1" = "status" ]

then       

if [ "${WLS_PID}" = "" ] ; then

echo "No pid - $SERVER_NAME is not running !"

exit 1

else

echo "$SERVER_NAME is running !"

exit 0

fi

fi

printf "Terminating $SERVER_NAME "

if [ "${WLS_PID}" = "" ] ; then

echo "No pid - $SERVER_NAME is not running !"

else         

kill -9 $WLS_PID

wait_for_pid removed

if [ -n "$try" ] ; then

echo " failed "

exit 1        

fi

echo " done ! "

exit 0

fi

#如果是停止命令,這裡不使用這個       

if [ "$1" = "stop" ]

then       

echo ""

else

#啟動命令

printf "Starting $SERVER_NAME "

if echo $SERVER_NAME|grep -q dmin ; then       

nohup sh $DOMAIN_PATH/bin/startWebLogic.sh &

else       

nohup sh $DOMAIN_PATH/bin/startManagedWebLogic.sh $SERVER_NAME $ADMIN_URL &

fi       

wait_for_pid created

if [ -n "$try" ] ; then

echo " failed "

exit 1

else

echo " done ! "

exit 0

fi  

fi

echo "To check the log, you may excute:"

echo "tail -100f "