Script example for starting and stopping spring boot projects in Linux

Script example for starting and stopping spring boot projects in Linux

There are three ways to start a springboot project:

1. Run the main method program

2. Use the command mvn spring-boot:run to run on the command line

3. After using mvn packpage to package the jar file, run it using the java -jar yourapp.jar command line

Generally, we often use the first two running modes when developing, and the third mode when deploying and implementing. Below we will focus on downloading the instructions and scripts for running and stopping the springboot project in the Linux environment:

1. Instructions

nohup does not hang up the run command

Generally, you can use it directly in Linux:

java -jar yourapp.jar

To start the program, but once the process is terminated, the program will immediately hang up, so in this case, we have to use nohup

nohup java -jar yourapp.jar > yourapp.out 2>&1 &

But the biggest problem is that it is inconvenient to manage. what to do?

Second, write a shell script

1. start.sh

#!/bin/bash
nohup java -jar yourapp.jar -Xms256m -Xmx1024m > yourapp.out 2>&1 &

2. stop.sh

#!/bin/bash
PID=$(ps -ef | grep yourapp.jar | grep -v grep | awk '{ print $2 }')
if [ ${PID} ]; 
then
 echo 'Application is stpping...'
 echo kill $PID DONE
 kill $PID
else
 echo 'Application is already stopped...'
fi

3. Integrate the start and stop scripts and write run.sh

#!/bin/bash
echo 'Application is stpping...'
source stop.sh
echo 'Application is running...'
source start.sh

binggo…

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Linux editing start, stop and restart springboot jar package script example
  • How to start and stop scripts for SpringBoot projects under Centos
  • Detailed explanation of spring boot starting common shell scripts in jar mode
  • Spring boot + LayIM + t-io to implement file upload and monitor user status example code
  • Detailed explanation of Spring boot custom http feedback status code
  • Spring Boot start, stop, restart, status scripts

<<:  Summary of 10 must-see JavaScript interview questions (recommended)

>>:  Detailed explanation of how to install MySQL on Alibaba Cloud

Recommend

Summary of several replication methods for MySQL master-slave replication

Asynchronous replication MySQL replication is asy...

Implementation of dynamic rem for mobile layout

Dynamic rem 1. First, let’s introduce the current...

Comparison of mydumper and mysqldump in mysql

If you only want to back up a few tables or a sin...

MySQL database import and export data error solution example explanation

Exporting Data Report an error SHOW VARIABLES LIK...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...

Detailed explanation of the solution to font blur when using transform in CSS3

This question is very strange, so I will go strai...

HTML blockquote tag usage and beautification

Blockquote Definition and Usage The <blockquot...

Nginx try_files directive usage examples

Nginx's configuration syntax is flexible and ...

Some CSS questions you may be asked during an interview

This article is just to commemorate those CSS que...

Solutions to the Problem of Creating XHTML and CSS Web Pages

The solutions to the problems encountered during x...

Learn one minute a day to use Git server to view debug branches and fix them

Debug branch During the normal development of a p...

How to implement the observer pattern in JavaScript

Table of contents Overview Application scenarios ...

MySQL simple example of sorting Chinese characters by pinyin

If the field storing the name uses the GBK charac...