springboot jar package zip file to play the way

1. Add package configuration file

1.1  assembly.xml

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
            <fileMode>0777</fileMode>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/conf</directory>
            <outputDirectory>/conf</outputDirectory>            
            <fileMode>0644</fileMode>
        </fileSet>
    </fileSets>
</assembly>
View Code

1.2  serverStatus.sh

#!/bin/sh
if [ ! -n "$JAVA_HOME" ]; then
    export JAVA_HOME="/export/server/jdk1.8.0_141"
fi
APP_MAIN=${application.main.class}
PID=0

getpid () {
    javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
    if [ -n "$javaps" ]; then
        PID=`echo $javaps | awk '{print $1}'`
    else
        PID=0
    fi
}

getServerStatus(){
    getpid
    echo "================================================================================================================"
    if [ $PID -ne 0 ]; then
        echo "$APP_MAIN is running(PID=$PID)"
        echo "================================================================================================================"
    else
        echo "$APP_MAIN is not running"
        echo "================================================================================================================"
    fi
}
getServerStatus
View Code

1.3  shutdown.sh

#!/bin/sh
if [ ! -n "$JAVA_HOME" ]; then
    export JAVA_HOME="/export/server/jdk1.8.0_141"
fi
APP_MAIN=${application.main.class}
PID=0

getpid () {
    javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
    if [ -n "$javaps" ]; then
        PID=`echo $javaps | awk '{print $1}'`
    else
        PID=0
    fi
}

shutdown(){
    getpid
    echo "================================================================================================================"
    if [ $PID -ne 0 ]; then
        echo -n "Stopping $APP_MAIN(PID=$PID)..."
        kill -9 $PID
        if [ $? -eq 0 ]; then
            echo "[Success]"
            echo "================================================================================================================"
        else
            echo "[Failed]"
            echo "================================================================================================================"
        fi
        getpid
        if [ $PID -ne 0 ]; then
            shutdown
        fi
    else
        echo "$APP_MAIN is not running"
        echo "================================================================================================================"
    fi
}

shutdown
View Code

1.4  startup.sh

#! / bin / SH 
# ------------------------------------------- -------------------------------------------------- ---------------- 
# use the script as -> [ SH . the Startup SH ]
# The script can be executed in any directory on the server will not affect the output location of the log, etc.
#-------------------------------------------------------------------------------------------------------------
if [ ! -n "$JAVA_HOME" ]; then
    export JAVA_HOME="/export/server/jdk1.8.0_141"
fi

#-------------------------------------------------------------------------------------------------------------
# System operating parameters
#-------------------------------------------------------------------------------------------------------------
DIR=$(cd "$(dirname "$0")"; pwd)
APP_HOME = $ {DIR} / ..
CLASSPATH=$APP_HOME/conf
APP_LOG=${APP_HOME}/logs
APP_CONFIG=${APP_HOME}/conf/application.yml
APP_MAIN=${application.main.class}

JAVA_OPTS="$JAVA_OPTS -server -Xms512m -Xmx512m -Xmn128m -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:MaxGCPauseMillis=850 -XX:+PrintGCDetails -Xloggc:$APP_LOG/gc.log -Dfile.encoding=UTF-8"
JAVA_OPTS="$JAVA_OPTS -DlogPath=$APP_LOG"
JAVA_OPTS="$JAVA_OPTS -Dconf.config=file:${APP_CONFIG}"

echo "JAVA_HOME="$JAVA_HOME
echo "CLASSPATH="$CLASSPATH
echo "JAVA_OPTS="$JAVA_OPTS

#-------------------------------------------------------------------------------------------------------------
# Program starts
#-------------------------------------------------------------------------------------------------------------
for appJar in "$APP_HOME"/lib/*.jar;
do
   CLASSPATH="$CLASSPATH":"$appJar"
done
PID=0

getpid () {
    javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
    if [ -n "$javaps" ]; then
        PID=`echo $javaps | awk '{print $1}'`
    else
        PID=0
    be
}

startup(){
    getpid
    echo "================================================================================================================"
    if [ $PID -ne 0 ]; then
        echo "$APP_MAIN already started(PID=$PID)"
        echo "================================================================================================================"
    else
        echo -n "Starting $APP_MAIN"
         if [ ! -d "$APP_LOG" ]; then
            mkdir "$APP_LOG"
         be
        nohup $JAVA_HOME/bin/java $JAVA_OPTS -classpath $CLASSPATH $APP_MAIN &
        for i in $(seq 5)
        do
        sleep 0.8
        echo -e  ".\c"
        done
        getpid
        if [ $PID -ne 0 ]; then
            echo "(PID=$PID)...[Success]"
            echo "================================================================================================================"
        else
            echo "[Failed]"
            echo "================================================================================================================"
        be
    be
}

startup
View Code

 

2. Package

 After executing the command generated at the zip target file path

 

3.linux start the service

Upload and extract the zip package

 

 Successful start

 

4. Test

 test was successful

 

Guess you like

Origin www.cnblogs.com/chong-zuo3322/p/12318603.html