前段时间用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

  

最新文章

  1. 开始我的IT博客之旅
  2. windows下安装easy_install, pip 及whl文件安装方法
  3. Linux下5种IO模型的小结
  4. 关于Android真机调测Profiler
  5. http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html
  6. 线段树(区间合并) POJ 3667 Hotel
  7. iOS开发——屏幕尺寸适配
  8. Sql Server使用正则表达式
  9. C# @字符用法
  10. ROS机器人程序设计(原书第2版)补充资料 (零) 源代码、资料和印刷错误修订等 2017年01月01日更新
  11. PHP 二维数组排序保持键名不变
  12. Linux必备150个命令
  13. selenium常用的模块
  14. LeetCode算法题-Merge Sorted Array(Java实现)
  15. MySQL数据库之auto_increment【转】
  16. 用jquery得到select选中的值
  17. JEECG 新手常见问题大全,入门必读
  18. Js_图片轮换
  19. windows配置承载网络的一个批处理程序
  20. 大龄码农那些事——也谈996.ICU

热门文章

  1. tomcat 部署指南
  2. 前端面试题:CSS实现水平垂直居中
  3. C++ begin()和end()
  4. spring boot 开静态资源访问,配置视图解析器
  5. win server2008关闭危险端口445,135,137,138,139的方法
  6. C#如何获取系统downloads和documents路径
  7. 三层for循环求解组成三角形边的组合
  8. Linux学习篇(一)-初识Linux
  9. Delphi IdHttp组件+IdHttpServer组件实现文件下载服务
  10. v-if指令