Source: author: junbaor segmentfault.com/a/119000001…

This script is used to manage the process state of the SpringBoot project.

Have prompt function.

Drop the script into the project folder and add execution permissions.

If Jenkins uses this script, you need to add BUILD_ID=dontKillMe before the java-jar command, otherwise Jenkins will kill the process.

Reference:

Stackoverflow.com/questions/3…

Script maintenance in Github, there is a need to pay attention to

Github.com/junbaor/she…

spring-boot.sh

#! /bin/bash SpringBoot=$2 if [ "$1" = "" ]; Then the echo - e "\ [0; 31 m not input operation 033\033 [0 m \ [0; 34 m 033 {start | stop | restart | status} \ 033 [0 m" exit 1 fi if [= "$SpringBoot" "\" "]; then the echo - e [0; 31 m not input application 033\033 [0 m "exit 1 fi function 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" esacCopy the code

Spring Boot example tutorial and source code has been uploaded:

Github.com/javastacks/…

Recent hot articles recommended:

1.1,000+ Java Interview Questions and Answers (2021)

2. I finally got the IntelliJ IDEA activation code thanks to the open source project. How sweet!

3. Ali Mock is officially open source, killing all Mock tools on the market!

4.Spring Cloud 2020.0.0 is officially released, a new and disruptive version!

5. “Java Development Manual (Songshan version)” the latest release, quick download!

Feel good, don’t forget to click on + forward oh!