这篇文章给大家介绍Spring Boot 项目脚本是怎样的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
此脚本用来管理 SpringBoot 项目的进程状态。有提示功能。把脚本丢到项目文件夹, 添加执行权限即可。
如果 jenkins 使用这个脚本, 需要在 java -jar 命令前添加 BUILD_ID=dontKillMe
, 不然 jenkins 会杀掉进程。
#!/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
下图是pdf版本的部分截图。
关于Spring Boot 项目脚本是怎样的就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/3852842/blog/4475368