修改打包部署文件
This commit is contained in:
@@ -24,8 +24,8 @@
|
|||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<outputDirectory>etc</outputDirectory>
|
<outputDirectory>etc</outputDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>application.yml</include>
|
<include>*.yml</include>
|
||||||
<include>logback.xml</include>
|
<include>*.xml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
|
||||||
|
|||||||
11
pom.xml
11
pom.xml
@@ -137,11 +137,14 @@
|
|||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>sql/**</exclude>
|
<exclude>sql/**</exclude>
|
||||||
|
<exclude>*.yml</exclude>
|
||||||
|
<exclude>*.xml</exclude>
|
||||||
|
<exclude>*.yaml</exclude>
|
||||||
|
<exclude>*.properties</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- 薄 jar:仅打包编译后的 class,输出到 target/libs/ -->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
@@ -150,8 +153,12 @@
|
|||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>com.label.LabelBackendApplication</mainClass>
|
<mainClass>com.label.LabelBackendApplication</mainClass>
|
||||||
<addClasspath>false</addClasspath>
|
<addClasspath>true</addClasspath>
|
||||||
|
<classpathPrefix>./</classpathPrefix>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<Class-Path>../etc/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# label-backend 启动脚本
|
|
||||||
# - Docker 环境(检测 /.dockerenv):exec 前台运行,保持容器进程存活
|
|
||||||
# - 裸机 / VM:nohup 后台运行,日志追加至 logs/startup.log
|
|
||||||
|
|
||||||
set -e
|
# 1. 获取脚本所在目录的绝对路径
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
BASEDIR=$(cd "$(dirname "$0")/.." && pwd)
|
# 2. 获取项目根目录 (假设 bin 在根目录下)
|
||||||
LIBDIR="$BASEDIR/libs"
|
APP_HOME="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
CONFDIR="$BASEDIR/etc"
|
|
||||||
LOGDIR="$BASEDIR/logs"
|
|
||||||
|
|
||||||
mkdir -p "$LOGDIR"
|
# 3. 【关键步骤】切换到项目根目录
|
||||||
|
# 这样相对路径 "logs" 就会指向 $APP_HOME/logs
|
||||||
|
cd "$APP_HOME"
|
||||||
|
|
||||||
JVM_OPTS="${JVM_OPTS:--Xms512m -Xmx1024m}"
|
# 4. 确保 logs 目录存在
|
||||||
MAIN_CLASS="com.label.LabelBackendApplication"
|
mkdir -p logs
|
||||||
JAVA_ARGS="$JVM_OPTS \
|
|
||||||
-Dspring.config.location=file:$CONFDIR/application.yml \
|
|
||||||
-Dlogging.config=file:$CONFDIR/logback.xml \
|
|
||||||
-cp $LIBDIR/*"
|
|
||||||
|
|
||||||
if [ -f /.dockerenv ]; then
|
# 5. 定义其他变量
|
||||||
# Docker 容器:exec 替换当前进程,PID=1 接管信号
|
JAR_FILE="$APP_HOME/libs/label-backend-1.0.0-SNAPSHOT.jar"
|
||||||
exec java $JAVA_ARGS $MAIN_CLASS
|
|
||||||
else
|
# 6. 启动应用
|
||||||
# 裸机 / VM:nohup 后台运行
|
nohup java -Xms512m -Xmx512m \
|
||||||
nohup java $JAVA_ARGS $MAIN_CLASS >> "$LOGDIR/startup.log" 2>&1 &
|
-jar "$JAR_FILE" \
|
||||||
echo "label-backend started, PID=$!"
|
> /dev/null 2>&1 &
|
||||||
fi
|
# 如果希望保留控制台日志备份,可以重定向到 $APP_HOME/logs/console.log
|
||||||
|
|
||||||
|
echo "Application started. Logs at: $APP_HOME/logs/"
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<!-- <appender-ref ref="CONSOLE"/> -->
|
||||||
<appender-ref ref="FILE"/>
|
<appender-ref ref="FILE"/>
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user