Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of Linux starting and stopping SpringBoot jar Program to deploy Shell script

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

No more nonsense, first give everyone the code, the specific code is as follows:

#! / bin/bashcd `JAR_PATH=$CUR_SHELL_DIR/$JAR_NAME#JAVA_MEM_OPTS= $0`cur _ SHELL_DIR= `pwd`cur _ SHELL_NAME= `basename ${BASH_SOURCE} `# modify the jar package name here to JAR_NAME= "xxxxxxxxxxxx.jar" JAR_PATH=$CUR_SHELL_DIR/$JAR_NAME#JAVA_MEM_OPTS= "- server-Xms1024m-Xmx1024m-XX:PermSize=128m" JAVA_MEM_OPTS= "# SPRING_PROFILES_ACTIV="-Dspring.profiles.active=eureka2 "SPRING_PROFILES_ACTIV="LOG_DIR=$CUR_SHELL_DIR/logsLOG_PATH=$LOG_DIR/$ {JAR_NAME}. Logecho_help () {echo-e "syntax: sh $CUR_SHELL_NAME start | stop"} if [- z $1] Then echo_help exit 1fiif [!-d "$LOG_DIR"]; then mkdir "$LOG_DIR" fiif [!-f "$LOG_PATH"]; then touch "$LOG_DIR" fiif ["$1" = = "start"]; then# check server PIDS= `ps-- no-heading-C java-f-- width 1000 | grep $JAR_NAME | awk'{print $2} '`if [- n "$PIDS"]; then echo-e "ERROR: The $JAR_NAME already started and the PID is ${PIDS}." Exit 1 fiecho "Starting the $JAR_NAME..." # start nohup java $JAVA_MEM_OPTS-jar $SPRING_PROFILES_ACTIV $JAR_PATH > > $LOG_PATH 2 > & 1 & COUNT=0 while [$COUNT-lt 1]; do sleep 1 COUNT= `ps-no-heading-C java-f-width 1000 | grep "$JAR_NAME" | awk'{print $2}'| wc-l`if [$COUNT-gt 0] Then break fi done PIDS= `ps-- no-heading-C java-f-- width 1000 | grep "$JAR_NAME" | awk'{print $2} '`echo "${JAR_NAME} Started and the PID is ${PIDS}." Echo "You can check the log file in ${LOG_PATH} for details." Elif ["$1" = = "stop"]; then PIDS= `ps-- no-heading-C java-f-- width 1000 | grep $JAR_NAME | awk'{print $2} '`if [- z "$PIDS"]; then echo "ERROR:The $JAR_NAME does not started!" Exit 1 fiecho-e "Stopping the $JAR_NAME..." For PID in $PIDS; do kill $PID > / dev/null 2 > & 1 done COUNT=0 while [$COUNT-lt 1]; do sleep 1 COUNT=1 for PID in $PIDS; do PID_EXIST= `ps-no-heading-p $PID`if [- n "$PID_EXIST"]; then COUNT=0 break fi done done echo-e "${JAR_NAME} Stopped and the PID is ${PIDS}." else echo_help exit 1fi

The above code can be used simply by changing the jar package name

Start the jar package:

. / xxxx.sh start

Stop the jar package

. / xxxx.sh stop

Summary

The above is the method that the editor introduces to you that Linux starts and stops the SpringBoot jar program to deploy the Shell script. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report