Aoto Deploy Project 1.0

相关文件比较多,正在整理中。。。

 预览版本

 

  1 [root@ins ~]# cat /opt/data/applications/dp2
  2 #!/bin/sh
  3 
  4 # Deployment project
  5 # Abbr. dp2
  6 
  7 echo2(){
  8         echo -e "\033[30;35m$*\033[0m"
  9 }
 10 
 11 # load config
 12 while read line; do
 13         eval "$line"
 14 done < ${0%%.*}.ini
 15 
 16 # check tomcat directory, executable
 17 CMD_RUN=$CATALINA_HOME/bin/startup.sh
 18 CMD_HALT=$CATALINA_HOME/bin/shutdown.sh
 19 CHECK_STATUS=-1
 20 if [ ! -d "$CATALINA_HOME" ]; then
 21         echo2 Not a directory. \'$CATALINA_HOME\'
 22 elif [ ! -d "$WEBAPPS_PATH" ]; then
 23         echo2 Not a directory. \'$WEBAPPS_PATH\'
 24 elif [ ! -e "$CMD_RUN" ]; then
 25         echo2 No such file. \'$CMD_RUN\'
 26 elif [ ! -x "$CMD_RUN" ]; then
 27         echo2 Not executable. \'$CMD_RUN\'
 28 elif [ ! -e "$CMD_HALT" ]; then
 29         echo2 No such file. \'$CMD_HALT\'
 30 elif [ ! -x "$CMD_HALT" ]; then
 31         echo2 Not executable. \'$CMD_HALT\'
 32 else
 33         CHECK_STATUS=0
 34 fi
 35 if [ $CHECK_STATUS -ne 0 ]; then
 36         exit
 37 fi
 38 
 39 # show usage
 40 WAR_FILE=$1
 41 if [ "$WAR_FILE" = "" ]; then
 42         echo Deployment project
 43         echo Note: Do not include spaces.
 44         echo Usage: ${0##*/} myweb1.war myweb2.war
 45         exit
 46 fi
 47 
 48 # stop server
 49 echo2 Stopping service...
 50 PROC_PART=catalina.home=$CATALINA_HOME
 51 PROC_NUM=`ps -ef | grep "$PROC_PART" | grep -v "grep $PROC_PART" | wc -l`
 52 echo2 PROC_NUM=$PROC_NUM
 53 if [ $PROC_NUM -eq 1 ]; then
 54         echo2 Detected a process and tried to kill it.
 55         $CMD_HALT
 56 elif [ $PROC_NUM -gt 1 ]; then
 57         echo2 Detected multiple processes, try to kill them.
 58         PROC_IDS=`ps -ef | grep "$PROC_PART" | grep -v "grep $PROC_PART" | awk '{print $2}'`
 59         echo2 PROC_IDS=$PROC_IDS
 60         if [ "$PROC_IDS" != "" ]; then
 61                 for i in $PROC_IDS
 62                 do
 63                         echo2 Probing process. $i
 64                         kill -0 $i
 65                         if [ $? -eq 0 ]; then
 66                                 echo2 Still exist. Inform it to quit.
 67                                 kill $i
 68                         else
 69                                 echo2 Has disappeared.
 70                         fi
 71                 done
 72         fi
 73 fi
 74 PROC_NUM=`ps -ef | grep "$PROC_PART" | grep -v "grep $PROC_PART" | wc -l`
 75 echo2 PROC_NUM=$PROC_NUM
 76 if [ $PROC_NUM -gt 0 ]; then
 77         echo2 Take enforcement measures after three seconds.
 78         sleep 3
 79         PROC_IDS=`ps -ef | grep "$PROC_PART" | grep -v "grep $PROC_PART" | awk '{print $2}'`
 80         echo2 PROC_IDS=$PROC_IDS
 81         if [ "$PROC_IDS" != "" ]; then
 82                 for i in $PROC_IDS
 83                 do
 84                         echo2 Forced end process. $i
 85                         kill -9 $i
 86                 done
 87         fi
 88 fi
 89 PROC_NUM=`ps -ef | grep "$PROC_PART" | grep -v "grep $PROC_PART" | wc -l`
 90 echo2 PROC_NUM=$PROC_NUM
 91 if [[ $PROC_NUM -gt 0 ]]; then
 92         echo2 Stop service failed.
 93         exit
 94 fi
 95 echo2 Service has stopped.
 96 
 97 # put project
 98 for i in $*
 99 do
100         CHECK_STATUS=-1
101         if [ ! -e "$i" ]; then
102                 echo2 No such file. \'$i\'
103         elif [ ! "${i##*.}" = "war" ]; then
104                 echo2 Not a WAR file. \'$i\'
105         else
106                 CHECK_STATUS=0
107         fi
108         if [ $CHECK_STATUS -ne 0 ]; then
109                 continue
110         fi
111         echo2 Deploying web application archive. \'$i\'
112         cp $i $WEBAPPS_PATH/
113         PRJ_NAME=${i##*/}
114         PRJ_PATH=$WEBAPPS_PATH/${PRJ_NAME%.*}
115         if [ -d $PRJ_PATH ]; then
116                 echo2 Delete released web application archive. \'$PRJ_PATH\'
117                 rm -rf $PRJ_PATH
118         fi
119 done
120 
121 # clean cache
122 rm -rf $CATALINA_HOME/work/*
123 rm -rf $CATALINA_HOME/logs/*
124 
125 # start server
126 echo2 Starting service...
127 $CMD_RUN
128 sleep 1
129 echo2 Deploy completed.
130 [root@ins ~]#

 

1 [root@ins ~]# cat /opt/data/applications/dp2.ini
2 # Currently: only support 'Tomcat'
3 TYPE=tomcat
4 CATALINA_HOME=/opt/apache-tomcat-7.0.47
5 WEBAPPS_PATH=/opt/apache-tomcat-7.0.47/webapps
6 [root@ins ~]#

 

posted @ 2019-07-09 18:36  RMS365  阅读(...)  评论(... 编辑 收藏