Browse Source

:bug: 启动脚本

Aron 6 years ago
parent
commit
d7121d2548
5 changed files with 112 additions and 30 deletions
  1. 5 0
      bin/shutdown.sh
  2. 6 0
      bin/startup.sh
  3. 101 0
      deploy.sh
  4. 0 0
      src/main/resources/application.properties
  5. 0 30
      src/main/resources/restart_boot.sh

+ 5 - 0
bin/shutdown.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+jarName=$1
+echo " ---  "
+ps -ef | grep ${jarName} | grep -v grep | grep -v deploy | awk '{print $2}' | xargs kill -9

+ 6 - 0
bin/startup.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+jarName=$1
+profile=$2
+
+nohup java -jar ../${jarName} --spring.profiles.active=${profile} >/dev/null 2>&1 &

+ 101 - 0
deploy.sh

@@ -0,0 +1,101 @@
+#!/bin/bash
+
+# 参数说明
+# $1 jarName 默认 ifast-1.0.0.jar
+# $2 branch 默认 dev
+# $3 appDir 默认 /home/server/webapps/ifast
+# $4 profile 激活的配置文件,默认dev
+
+#
+# step 1.
+#
+
+# $1
+# jar名称默认
+jarName=$1
+if [ -z "${jarName}" ]
+then
+    jarName=ifast-1.0.0.jar
+fi
+echo "jarName: ${jarName}"
+
+# $2
+# 将指定分支最新代码部署到指定目录。默认dev
+# 如果目录不存在会自动创建。
+
+branch=$2
+
+if [ -z "${branch}" ]
+then
+    branch=dev
+fi
+echo "branch: ${branch}"
+
+# $3
+appDir=$3
+if [ -z "${appDir}" ]
+then
+    appDir=/home/server/webapps/ifast
+fi
+
+if [ ! -d ${appDir} ]
+then
+    echo "目录 ${appDir} 不存在,尝试创建 ..."
+    mkdir -p ${appDir}
+fi
+
+echo "appDir: ${appDir}"
+
+# $4
+profile=$4
+if [ -z "${profile}" ]
+then
+    profile=dev
+fi
+echo "profile: ${profile}"
+
+#
+# step 2.
+#
+
+srcDir=`pwd`
+
+git pull origin ${branch}
+
+mvn install
+
+#
+# step 3. shutdown > delete | backup
+#
+
+cd ${appDir}
+echo "shutdown ..."
+if [ -d "bin" ]
+then
+    cd bin
+    ./shutdown.sh ${jarName}
+    ps -ef | grep ${jarName}
+    cd ..
+fi
+
+
+echo "del ${appDir}/${jarName}"
+rm -f ${jarName}
+echo "del ${appDir}/bin"
+rm -rf bin
+
+# move | copy > chmod
+echo "move ${srcDir}/target/${jarName} to ${appDir}"
+mv ${srcDir}/target/${jarName} ${appDir}
+
+echo "copy dir ${srcDir}/bin to `pwd`"
+cp -R ${srcDir}/bin .
+chmod u+x ${appDir}/bin/*
+
+#
+# step 4. start
+#
+
+echo "startup ..."
+cd bin
+./startup.sh ${jarName} ${profile}

+ 0 - 0
src/main/resources/application.properties


+ 0 - 30
src/main/resources/restart_boot.sh

@@ -1,30 +0,0 @@
-export JAVA_HOME=/home/jdk1.8.0_111
-export PATH=$JAVA_HOME/bin:$PATH
-export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
-
-Port=8087
-JarName=ifast-1.0.0.jar-8088.jar
-LogsPatch=./logs_$Port
-
-
-ID=`ps -ef | grep $Port | grep -v "grep" | awk '{print $2}'`  
-echo $ID  
-echo "---------------"  
-for id in $ID  
-do  
-kill -s 9 $id  
-echo "killed $id"  
-done  
-echo "---------------"  
-
-rm -rf $LogsPatch
-mkdir $LogsPatch
-
-export LANG=zh_CN.UTF-8
-
-set -m 
-
-nohup java -jar -Dlogging.path=$LogsPatch  $JarName>$LogsPatch/catlina.out 2>&1 &
-
-tail -f $LogsPatch/catlina.out
-