编译和启动脚本升级

This commit is contained in:
马超 2021-01-25 21:16:38 +08:00
parent 5253791bed
commit 52d13ff05b
9 changed files with 321 additions and 35 deletions

View File

@ -0,0 +1,38 @@
<assembly>
<id>assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/script</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>*.*</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
<!-- copy本工程的jar -->
<fileSet>
<directory>target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>

View File

@ -72,21 +72,55 @@
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- </plugin>-->
<!--排除静态文件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- 添加index则不从mainfest中读取classpath而是从Index.list中读取 -->
<!-- <index>true</index> -->
<manifest>
<mainClass>com.qiwenshare.file.FileApplication</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<excludes>
<exclude>static/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- not append assembly id in release file name -->
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>../file-common/src/main/resources/conf/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!--ant插件执行自定义动作-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -99,15 +133,15 @@
</goals>
<configuration>
<target>
<copy file="target/${app-name}.jar" tofile="${release-path}/app/${project.artifactId}/${app-name}.jar" />
<copy file="target/classes/script/startup.bat" tofile="${release-path}/startup.bat"/>
<copy file="target/classes/script/startup.sh" tofile="${release-path}/startup.sh"/>
<copy file="target/classes/script/stop.sh" tofile="${release-path}/stop.sh"/>
<copy todir="${release-path}">
<fileset dir="target/classes">
<include name="**/static/**" />
</fileset>
</copy>
<copy file="target/${app-name}.zip" tofile="${release-path}/${app-name}.zip" />
<!-- <copy file="target/classes/script/startup.bat" tofile="${release-path}/startup.bat"/>-->
<!-- <copy file="target/classes/script/startup.sh" tofile="${release-path}/startup.sh"/>-->
<!-- <copy file="target/classes/script/stop.sh" tofile="${release-path}/stop.sh"/>-->
<!-- <copy todir="${release-path}">-->
<!-- <fileset dir="target/classes">-->
<!-- <include name="**/static/**" />-->
<!-- </fileset>-->
<!-- </copy>-->
</target>
</configuration>
</execution>

View File

@ -1,2 +0,0 @@
java -jar app/file-web/file-web-1.0.0-SNAPSHOT.jar
pause

View File

@ -1,8 +0,0 @@
#!/bin/bash
BUILD_ID=dontKillMe
nohup java -jar app/file-web/file-web-1.0.0-SNAPSHOT.jar --server.port=8763 &

View File

@ -1,11 +0,0 @@
#!/bin/bash
PID=$(ps -ef | grep app/file-web |grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi

View File

@ -0,0 +1,4 @@
#!/bin/bash
cd `dirname $0`
./stop.sh $*
./start.sh $*

View File

@ -0,0 +1,139 @@
#!/bin/bash
. /etc/profile
. ~/.bashrc
. ~/.bash_profile
#support jsch commons
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
SPRING_PROFILES_ACTIVE="dev"
export SPRING_PROFILES_ACTIVE
echo "-------- SPRING_PROFILES_ACTIVE ${SPRING_PROFILES_ACTIVE}--------"
echo "--------start app ${DEPLOY_DIR}--------"
PARENT_DIR=$(dirname "$PWD")
CONF_DIR=$DEPLOY_DIR/conf
LIB_DIR=$DEPLOY_DIR/lib
SERVER_NAME=`cat $CONF_DIR/config/application.yml | grep -w "name:" | grep -v "#" | awk 'NR==1{print $2}' | tr -d '\r'`
SERVER_PORT=`cat $CONF_DIR/config/application.yml | grep -w "port:" | grep -v "#" | awk 'NR==1{print $2}' | tr -d '\r'`
#REM **********************************************************************************************
LOG_PATH="/export/log/qiwen-file"
GC_LOG_PATH="/export/log/qiwen-file/gc"
if [ "${LOG_PATH}" == "" ] ; then
LOG_PATH=$PARENT_DIR/logs/${SERVER_NAME}
fi
if [ "${GC_LOG_PATH}" == "" ] ; then
GC_LOG_PATH=$PARENT_DIR/logs/${SERVER_NAME}/gclog
fi
if [ ! -d ${LOG_PATH} ];then
mkdir -p ${LOG_PATH}
fi
if [ ! -d ${GC_LOG_PATH} ];then
mkdir -p ${GC_LOG_PATH}
fi
STDOUT_FILE=${LOG_PATH}/nohup.out
#if use self jdk,modify
#JAVA_HOME="/usr/lib/jvm/jdk1.8.0_191"
if [ "${JAVA_HOME}" != "" ] ; then
export JAVA_HOME
export PATH=$PATH:JAVA_HOME/bin
echo JAVA_HOME:${JAVA_HOME}
else
echo "JAVA_HOME not set!!!"
exit 1
fi
USER_VMARGS="-D64 -server -Xmx1g -Xms1g -Xmn521m -Xss256k "
#GC_OPTS=""
GC_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_PATH/heapdump.$$.hprof -XX:ErrorFile=$LOG_PATH/hs_err_pid$$.log -Xloggc:$GC_LOG_PATH/gc.$$.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC "
JMX_PORT=""
JAVA_JMX_OPTS=""
if [ "${JMX_PORT}" != "" ] ; then
JAVA_JMX_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=${JMX_PORT} "
fi
#JAVA_DEBUG=""
#if [ "$1" = "debug" ]; then
# JAVA_DEBUG=" -Xdebug "
#fi
JAVA_OPTS=""
#if [ "${JAVA_OPTS}" != "" ]; then
# JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
#fi
#REM **********************************************************************************************
#prevent repeated start
PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
exit 1
fi
if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
exit 1
fi
fi
#=====================
######################cloud trace##########################
TRACE_CLOUD_TRACE_URL=http://localhost:9411
TRACE_CLOUD_TRACE_PROBABILITY=1.0
TRACE_CLOUD_TRACE_ENABLED=true
TRACE_LIB_JARS="/opt/cloud-trace-deps-1.1.0/*"
echo "Using TRACE_LIB_JARS: $TRACE_LIB_JARS"
if [ -n "$TRACE_CLOUD_TRACE_URL" ]; then
TRACE_OPTS="-Dcloud.trace.url=$TRACE_CLOUD_TRACE_URL"
fi
if [ -n "$TRACE_CLOUD_TRACE_PROBABILITY" ]; then
TRACE_OPTS="$TRACE_OPTS -Dcloud.trace.probability=$TRACE_CLOUD_TRACE_PROBABILITY"
fi
if [ -n "$TRACE_CLOUD_TRACE_ENABLED" ]; then
TRACE_OPTS="$TRACE_OPTS -Dcloud.trace.enabled=$TRACE_CLOUD_TRACE_ENABLED"
fi
#echo "Using TRACE_OPTS: $TRACE_OPTS"
##########################################################
LIB_JARS=$DEPLOY_DIR/lib/*
echo "Using LIB_JARS: $LIB_JARS"
echo "Using CONF_DIR: $CONF_DIR"
echo "Using TRACE_LIB_JARS: $TRACE_LIB_JARS"
CLASSPATH=".:$CONF_DIR:$LIB_JARS:$TRACE_LIB_JARS"
EXEC_CMDLINE="${JAVA_HOME}/bin/java -classpath ${CLASSPATH} ${TRACE_OPTS} ${USER_VMARGS} ${GC_OPTS} ${JAVA_JMX_OPTS} ${JAVA_DEBUG} ${JAVA_OPTS} com.qiwenshare.file.FileApplication"
echo "Start app command line: ${EXEC_CMDLINE}" >> $STDOUT_FILE
echo "Starting $SERVER_NAME ..."
nohup ${EXEC_CMDLINE} >> $STDOUT_FILE 2>&1 &
###wait app start listener port, only wait 120s
COUNT=0
while [ $COUNT -lt 120 ]; do
echo -e ".\c"
sleep 1
IS_LISTENED=`netstat -an | grep -w LISTEN | grep -w $SERVER_PORT`
let COUNT++
if [ -n "$IS_LISTENED" ]; then
COUNT=1000
fi
done
echo "Console File: $STDOUT_FILE"
echo "--------start app $SERVER_NAME on $(uname -n) (pid=$$)--------"

View File

@ -0,0 +1,63 @@
#!/bin/bash
. /etc/profile
. ~/.bashrc
. ~/.bash_profile
#support jsch commons
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
echo "========stop app ${DEPLOY_DIR}========"
PARENT_DIR=$(dirname "$PWD")
CONF_DIR=$DEPLOY_DIR/conf
LIB_DIR=$DEPLOY_DIR/lib
SERVER_NAME=`cat $CONF_DIR/config/application.yml | grep -w "name:" | grep -v "#" | awk 'NR==1{print $2}' | tr -d '\r'`
SERVER_PORT=`cat $CONF_DIR/config/application.yml | grep -w "port:" | grep -v "#" | awk 'NR==1{print $2}' | tr -d '\r'`
#REM **********************************************************************************************
LOG_PATH="/export/log/qiwen-file"
if [ "${LOG_PATH}" == "" ] ; then
LOG_PATH=$PARENT_DIR/logs/${SERVER_NAME}
fi
STDOUT_FILE=$LOG_PATH/nohup.out
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
fi
#REM **********************************************************************************************
echo "Stopping the $SERVER_NAME ..."
echo "Stopping the $SERVER_NAME" >> $STDOUT_FILE
date>>$STDOUT_FILE
id>>$STDOUT_FILE
echo $SERVER_NAME shutdown , pids $PIDS >> $STDOUT_FILE
for PID in $PIDS ; do
kill $PID
done
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
for PID in $PIDS ; do
PID_EXIST=`ps -f -p $PID | grep java`
if [ -n "$PID_EXIST" ]; then
COUNT=0
break
fi
done
done
echo "PID: $PIDS has bean kill" >> $STDOUT_FILE
echo "========stop app $SERVER_NAME shutdown========"

View File

@ -0,0 +1,29 @@
@echo off & setlocal enabledelayedexpansion
rem if need special jdk
rem JAVA_HOME="c:\Java\jdk1.8.0_191\"
rem PATH=%JAVA_HOME%\bin;%PATH%
rem enter app deploy path
cd ..\
set DEPLOY_PATH=%cd%
set CONF_DIR=%DEPLOY_PATH%/conf
set LIB_JARS=%DEPLOY_PATH%/lib/*
set LOG_PATH=%DEPLOY_PATH%/logs
set CLASSPATH=".;%CONF_DIR%;%LIB_JARS%"
set JAVA_VM=-D64 -server -Xmx512m -Xms512m -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
set JAVA_OPTIONS=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8231
echo DEPLOY_PATH: %DEPLOY_PATH%
echo CLASSPATH=%CLASSPATH%
echo "Start App..."
java -version
java %JAVA_VM% %JAVA_OPTIONS% -classpath %CLASSPATH% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8336 com.qiwenshare.file.FileApplication
goto end
:end
pause