jar 启动脚本
2024-09-07 17:26:24
前段时间用springboot做项目后,每次重新发布都好麻烦, 所以写了个脚本来配合jenkins 发布;
#!/bin/bash APP_NAME=application.jar function check {
local PID=0
if [ -e tpid ] ;then
PID=$(cat tpid)
# while read TMPID; do PID=$TMPID ;done < tpid
fi
# echo "PID:$PID"
if ps -p $PID > /dev/null ;then
echo $PID
else
echo 0
fi
}
function isRun {
local PID=$(check)
if [ $PID -ne 0 ]; then
echo "application is running..."
else
echo "application is not running..."
fi
} function start {
if [ ! -e $APP_NAME ]; then
echo "$APP_NAME is not found!"
return 0
fi local PID=$(check)
if [ $PID -ne 0 ]; then
echo "$PID $APP_NAME was running..."
return 0
fi local argumet=""
if [ -e application.properties ] ;then
argumet="$argumet --spring.config.location=application.properties"
fi
nohup java -jar $APP_NAME $argumet > log.out 2>&1 &
echo $! > tpid
PID=$(cat tpid)
echo $PID Start Success!
} function stop {
local PID=$(check)
if [ $PID -ne 0 ]; then
echo -n "Stop Process..."
kill -15 $PID
num=0
while [[ num -le 5 ]]; do
# echo $num
echo -n "."
sleep 1
PID=$(check)
if [ $PID -eq 0 ]; then
echo "Success!"
return 0
fi
num=$[ $num + 1 ]
done
PID=$(check)
if [ $PID -ne 0 ]; then
kill -9 $PID
echo ""
echo "Kill Process!"
else
echo "Success!"
fi
return 0
fi
return 1
} function restart {
stop
start
} function deploy {
fd=$(date +"%Y%m%d%H%M%S")
fileCount=`ls ./target/ | grep .jar$ | wc -l`
if [ $fileCount -eq 1 ]; then
fileName=`ls ./target/ | grep .jar$`
newName="$fileName.$fd"
mv ./target/$fileName ./target/$newName
if [ -e ./$APP_NAME ]; then
rm -rf ./$APP_NAME
fi
ln -s ./target/$newName ./$APP_NAME
echo "deploy success..."
restart
else
echo "Can not be deploy, jar file $fileCount"
return 1
fi
} case $1 in
"start" ) start;;
"stop" ) stop;;
"check" ) isRun;;
"restart" ) restart;;
"deploy" ) deploy;;
* ) echo "$0 start"
echo "$0 stop"
echo "$0 check"
echo "$0 restart"
echo "$0 deploy"
esac exit 0
最新文章
- 开始我的IT博客之旅
- windows下安装easy_install, pip 及whl文件安装方法
- Linux下5种IO模型的小结
- 关于Android真机调测Profiler
- http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html
- 线段树(区间合并) POJ 3667 Hotel
- iOS开发——屏幕尺寸适配
- Sql Server使用正则表达式
- C# @字符用法
- ROS机器人程序设计(原书第2版)补充资料 (零) 源代码、资料和印刷错误修订等 2017年01月01日更新
- PHP 二维数组排序保持键名不变
- Linux必备150个命令
- selenium常用的模块
- LeetCode算法题-Merge Sorted Array(Java实现)
- MySQL数据库之auto_increment【转】
- 用jquery得到select选中的值
- JEECG 新手常见问题大全,入门必读
- Js_图片轮换
- windows配置承载网络的一个批处理程序
- 大龄码农那些事——也谈996.ICU