博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 项目脚本(启动、停止、重启、状态)
阅读量:7095 次
发布时间:2019-06-28

本文共 1688 字,大约阅读时间需要 5 分钟。

  hot3.png

此脚本用来管理 SpringBoot 项目的进程状态。有提示功能。把脚本丢到项目文件夹, 添加执行权限即可。

如果 jenkins 使用这个脚本, 需要在 java -jar 命令前添加 BUILD_ID=dontKillMe , 不然 jenkins 会杀掉进程。

参考: 

脚本维护在 github, 有需求的话可以关注:

spring-boot.sh

#!/bin/bashSpringBoot=$2if [ "$1" = "" ];then    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"    exit 1fiif [ "$SpringBoot" = "" ];then    echo -e "\033[0;31m 未输入应用名 \033[0m"    exit 1fifunction start(){    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`    if [ $count != 0 ];then        echo "$SpringBoot is running..."    else        echo "Start $SpringBoot success..."        nohup java -jar $SpringBoot > /dev/null 2>&1 &    fi}function stop(){    echo "Stop $SpringBoot"    boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`    if [ $count != 0 ];then        kill $boot_id        count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`        boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`        kill -9 $boot_id    fi}function restart(){    stop    sleep 2    start}function status(){    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`    if [ $count != 0 ];then        echo "$SpringBoot is running..."    else        echo "$SpringBoot is not running..."    fi}case $1 in    start)    start;;    stop)    stop;;    restart)    restart;;    status)    status;;    *)    echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {SpringBootJarName} \033[0m\033[0;31m Example: \033[0m      \033[0;33m sh  $0  start esmart-test.jar \033[0m"esac

转载于:https://my.oschina.net/itlzm/blog/1922607

你可能感兴趣的文章
DirectX11 SDK 下载地址
查看>>
solr4.5分组查询、统计功能介绍
查看>>
优秀的 Spring Cloud 开源软件
查看>>
mysql数据库的简单语句的介绍(1)
查看>>
Spring framework3.2整合hibernate4.1报错:No Session found for current thread
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
[经验]无线鼠标和无线键盘真的不能用了?——雷柏的重生之路~
查看>>
Newtonsoft.Json 用法
查看>>
最强科技实力支撑海尔走出“全球化”道路
查看>>
微信小程序异步API为Promise简化异步编程
查看>>
关于java泛型大大小小的那些事
查看>>
Spring AOP不拦截从对象内部调用的方法原因
查看>>
Feign 与 Hystrix
查看>>
新旧之争,JDK 团队发起 Project Skara 引争议
查看>>
sudo、磁盘配额、数组、信号捕捉
查看>>
Azure负载均衡机制与会话粘滞需求
查看>>
Linux命令详解
查看>>
Quartz Job Scheduling Framework Reading Note(四)
查看>>
QTP的那些事--有关一个webtable数据的获取案例
查看>>
【原创】开源.NET排列组合组件KwCombinatorics使用(一)—组合生成
查看>>