[*] 优化脚本

This commit is contained in:
acgist
2023-06-14 10:53:44 +08:00
parent 4731c53d9d
commit 1fb00625b0
5 changed files with 95 additions and 86 deletions

View File

@@ -1,61 +1,61 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>prd</id> <id>prd</id>
<formats> <formats>
<format>zip</format> <format>zip</format>
</formats> </formats>
<includeBaseDirectory>false</includeBaseDirectory> <includeBaseDirectory>false</includeBaseDirectory>
<fileSets> <fileSets>
<fileSet> <fileSet>
<directory>${taoyao.maven.basedir}/docs</directory> <directory>${taoyao.maven.basedir}/docs</directory>
<outputDirectory>./</outputDirectory> <outputDirectory>./</outputDirectory>
<includes> <includes>
<include>README.md</include> <include>README.md</include>
</includes> </includes>
</fileSet> </fileSet>
<fileSet> <fileSet>
<directory>${taoyao.maven.basedir}/docs/bin</directory> <directory>${taoyao.maven.basedir}/docs/bin</directory>
<outputDirectory>bin</outputDirectory> <outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode> <fileMode>0755</fileMode>
<filtered>true</filtered> <filtered>true</filtered>
</fileSet> </fileSet>
<fileSet> <fileSet>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<outputDirectory>config</outputDirectory> <outputDirectory>config</outputDirectory>
<filtered>true</filtered> <filtered>true</filtered>
<includes> <includes>
<include>*.yml</include> <include>*.yml</include>
<include>*.properties</include> <include>*.properties</include>
</includes> </includes>
</fileSet> </fileSet>
<fileSet> <fileSet>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<outputDirectory>config</outputDirectory> <outputDirectory>config</outputDirectory>
<includes> <includes>
<include>*.cer</include> <include>*.cer</include>
<include>*.jks</include> <include>*.jks</include>
<include>*.p12</include> <include>*.p12</include>
<include>*.pfx</include> <include>*.pfx</include>
</includes> </includes>
</fileSet> </fileSet>
<fileSet> <fileSet>
<directory>target</directory> <directory>target</directory>
<outputDirectory>logs</outputDirectory> <outputDirectory>logs</outputDirectory>
<excludes> <excludes>
<exclude>**/*</exclude> <exclude>**/*</exclude>
</excludes> </excludes>
</fileSet> </fileSet>
</fileSets> </fileSets>
<dependencySets> <dependencySets>
<dependencySet> <dependencySet>
<outputDirectory>lib</outputDirectory> <outputDirectory>lib</outputDirectory>
</dependencySet> </dependencySet>
</dependencySets> </dependencySets>
</assembly> </assembly>

View File

@@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#########################
# 部署任务 #
#########################
# 进入目录 # 进入目录
base=$(readlink -f $(dirname $0)) base=$(readlink -f $(dirname $0))
cd $base cd $base
@@ -7,20 +11,16 @@ echo "环境目录:$base"
echo "当前目录:$(pwd)" echo "当前目录:$(pwd)"
# 更新代码 # 更新代码
if [ -z "$gited" ]; then echo "更新代码:${project.artifactId}-${project.version}"
echo "更新代码:${project.artifactId}-${project.version}" git pull
git pull
fi
# 编译代码 # 编译代码
if [ -z "$mvned" ]; then echo "编译代码:${project.artifactId}-${project.version}"
echo "编译代码:${project.artifactId}-${project.version}" mvn clean package -D skipTests -P ${profile}
mvn clean package -D skipTests -P ${profile} # 编译指定模块以及依赖
# 指定编译模块以及依赖
# mvn clean package -pl "${project.groupId}:${project.artifactId}" -am -D skipTests -P ${profile} # mvn clean package -pl "${project.groupId}:${project.artifactId}" -am -D skipTests -P ${profile}
fi
# 删除文件:注意不要删除日志 # 删除文件
rm -rf $base/deploy/bin rm -rf $base/deploy/bin
rm -rf $base/deploy/lib rm -rf $base/deploy/lib
rm -rf $base/deploy/config rm -rf $base/deploy/config
@@ -37,4 +37,4 @@ cp -rf ${project.basedir}/target/${project.artifactId}-${project.version}/* $bas
# 启动服务 # 启动服务
echo "启动项目:${project.artifactId}-${project.version}" echo "启动项目:${project.artifactId}-${project.version}"
sudo systemctl restart taoyao-signal-server sudo systemctl restart taoyao-signal-server
systemctl status taoyao-signal-server sudo systemctl status taoyao-signal-server

View File

@@ -1,19 +1,24 @@
#!/bin/bash #!/bin/bash
#########################
# 开始任务 #
#########################
# 启动目录 # 启动目录
bin=$(readlink -f $(dirname $0)) bin=$(readlink -f $(dirname $0))
base=${bin%/*} base=${bin%/*}
cd $base cd $base
echo "启动目录:$base" echo "环境目录:$base"
echo "启动目录:$(pwd)"
# 结束任务 # Java运行环境
if [ ! -f "/.dockerenv" ]; then if [ ! -f "/.dockerenv" ]; then
# Java运行环境
JAVA=$(which java) JAVA=$(which java)
if [ -z "$JAVA" ] ; then if [ -z "$JAVA" ] ; then
echo "必须安装${java.version}+JDK" echo "必须安装${java.version}+JDK"
exit 1 exit 1
fi fi
# 结束任务
bash bin/stop.sh bash bin/stop.sh
else else
JAVA="java" JAVA="java"
@@ -30,10 +35,8 @@ echo "启动参数:$JAVA_OPTS"
# 启动应用 # 启动应用
echo "启动应用:${project.artifactId}-${project.version}" echo "启动应用:${project.artifactId}-${project.version}"
if [ ! -f "/.dockerenv" ]; then if [ ! -f "/.dockerenv" ]; then
# 其他启动
nohup $JAVA $JAVA_OPTS -jar $base/lib/${project.artifactId}-${project.version}.jar > /dev/null 2>&1 & nohup $JAVA $JAVA_OPTS -jar $base/lib/${project.artifactId}-${project.version}.jar > /dev/null 2>&1 &
else else
# 使用docker启动后台启动不能查看控制台的信息
$JAVA $JAVA_OPTS -jar $base/lib/${project.artifactId}-${project.version}.jar $JAVA $JAVA_OPTS -jar $base/lib/${project.artifactId}-${project.version}.jar
fi fi

View File

@@ -1,8 +1,11 @@
#!/bin/bash #!/bin/bash
# 结束任务 #########################
# 结束任务 #
#########################
killIndex=0 killIndex=0
processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk '{print $2}') processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk "{print $2}")
if [ ! -z "$processId" ]; then if [ ! -z "$processId" ]; then
echo "关闭应用:${project.artifactId}-${project.version} - $processId" echo "关闭应用:${project.artifactId}-${project.version} - $processId"
while [ ! -z "$processId" ] while [ ! -z "$processId" ]
@@ -12,13 +15,13 @@ if [ ! -z "$processId" ]; then
# 优雅关机 # 优雅关机
kill -15 $processId kill -15 $processId
elif [ $killIndex -ge 10 ]; then elif [ $killIndex -ge 10 ]; then
echo -n '强制关闭'
# 强制关机 # 强制关机
echo -n "强制关闭"
kill -9 $processId kill -9 $processId
fi fi
sleep 1 sleep 1
killIndex=$((killIndex+1)) killIndex=$((killIndex+1))
processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk '{print $2}') processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk "{print $2}")
done done
echo "" echo ""
fi fi

View File

@@ -1,37 +1,40 @@
#!/bin/bash #!/bin/bash
# 休眠一秒:等待后台任务调度 #########################
sleep 1 # 等待任务 #
#########################
# 等待任务 # 休眠一秒:等待后台任务调度
startTime=$(date +%s) sleep 2
processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk '{print $2}') aTime=$(date +%s)
processPortNumber=0 processCt=0
processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk "{print $2}")
if [ ! -z "$processId" ]; then if [ ! -z "$processId" ]; then
echo "等待应用:${project.artifactId}-${project.version} - $processId"
waitIndex=0 waitIndex=0
processPortNumber=$(netstat -anop | grep $processId | grep LISTEN | wc -l) processCt=$(netstat -anop | grep $processId | grep LISTEN | wc -l)
while [ $waitIndex -le 120 ] && [ ! -z "$processId" ] && [ $processPortNumber -lt 1 ] while [ ! -z "$processId" ] && [ $processCt -lt 1 ] && [ $waitIndex -le 120 ]
do do
sleep 1 sleep 1
waitIndex=$((waitIndex+1)) waitIndex=$((waitIndex+1))
processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk '{print $2}') processId=$(ps -aux | grep "${project.artifactId}" | grep java | awk "{print $2}")
if [ ! -z "$processId" ]; then if [ ! -z "$processId" ]; then
processPortNumber=$(netstat -anop | grep $processId | grep LISTEN | wc -l) processCt=$(netstat -anop | grep $processId | grep LISTEN | wc -l)
else else
processPortNumber=0 processCt=0
fi fi
echo -n "." echo -n "."
done done
echo "" echo ""
fi fi
if [ $processPortNumber -lt 1 ]; then if [ $processCt -lt 1 ]; then
echo -e "\033[31m启动失败${project.artifactId}-${project.version}\033[0m" echo -e "\033[31m启动失败${project.artifactId}-${project.version} - $processId\033[0m"
bash bin/stop.sh bash bin/stop.sh
exit 0 exit 0
else else
finishTime=$(date +%s) zTime=$(date +%s)
processTime=$((finishTime-startTime)) cTime=$((finishTime-aTime))
echo -e "\033[32m启动成功${project.artifactId}-${project.version} - $processId\033[0m" echo -e "\033[32m启动成功${project.artifactId}-${project.version} - $processId\033[0m"
echo "启动端口:$(netstat -anop | grep $processId | grep LISTEN | awk '{print $4}')" echo "启动端口:$(netstat -anop | grep $processId | grep LISTEN | awk "{print $4}")"
echo "启动耗时:$processTime S" echo "启动耗时:$cTime S"
fi fi