文章中用到的application.sh 可参考:
https://blog.csdn.net/qq_32415063/article/details/105568986
#!/bin/bash
# 文件目录,应用程序包的地址
appDir=/appdata/spring-test
# 设置需要检测的文件路径
fileName=find . -name $appDir/*.jar
# 获取当前文件最后编辑时间戳
startTime=`stat -c %Y $appDir/$fileName`
# 循环检查文件更新时间
while true
do
changeTime=`stat -c %Y $appDir/$fileName`
if [ $lastTime -eq $startTime ];then
echo $(date) $appDir/$fileName 'not change'
else
startTime=$lastTime
echo $(date) $appDir/$fileName 'has been changed'
#重启脚本
sh $appDir/bin/application.sh restart
fi
# 检测间隔
sleep 5
done

本文介绍了一种使用bash脚本实时监控应用程序文件更新的方法,并在检测到更新后自动重启应用,确保应用始终运行最新版本。通过设置文件路径和定时检查,此脚本适用于各种基于JAR包的应用。

1160

被折叠的 条评论
为什么被折叠?



