If Spring Boot runs in a production environment, if it is packaged as a jar with maven, then shut down and restart the service, which is very inconvenient every time you operate. Here, a shell script is written for unified management.
# description: Auto-starts boot Tag="PublishImageApplication" MainClass="com.yoke.PublishImageApplication" Lib="/test/lib/" Log="/test/run.log" echo $Tag RETVAL="0" # See how we were called. function start() { echo $Log if [ ! -f $Log ]; then touch $Log be nohup java -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass > $Log 2>&1 & tailf $Log } function stop() { pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') if [ "$pid" != "" ]; then echo -n "boot ( pid $pid) is running" echo echo -n $"Shutting down boot: " pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') if [ "$pid" != "" ]; then echo "kill boot process" kill -9 "$pid" be else echo "boot is stopped" be status } function status() { pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') #echo "$pid" if [ "$pid" != "" ]; then echo "boot is running,pid is $pid" else echo "boot is stopped" be } function usage() { echo "Usage: $0 {start|stop|restart|status}" RETVAL="2" } # See how we were called. RETVAL="0" case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) RETVAL="3" ;; status) status ;; *) usage ;; esac exit $RETVAL
Tag: It plays a role in identifying the program running flag. If the server runs multiple java programs, you need to use java -Dappliction to distinguish the corresponding programs
MainClass: is the SpringBoot main class that corresponds to the running of the program
Lib: is all the jar paths of the boot program in the production server environment
Log: is to record the boot program running all log storage paths
For example, the script starts the command in
/boot/run_boot.sh
: /boot/run_boot.sh start
Restart command: /boot/run_boot.sh restart
Shutdown command: /boot/run_boot.sh stop
is it running: /boot/run_boot.sh status
Article source: http://blog.csdn.net/jiangzeyin_/article/details/74671334