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

How to make React components full screen

introduce This article is based on React + antd t...

javascript countdown prompt box

This article example shares the specific code of ...

HTML basics summary recommendation (paragraph)

HTML Paragraph Paragraphs are defined by the <...

js+Html to realize table editable operation

This article shares the specific code of js+Html ...

Ajax responseText parses json data case study

Solve the problem that the responseText returned ...

MySQL 8.0.16 Win10 zip version installation and configuration graphic tutorial

This article shares with you the installation and...

How to use localStorage in JavaScript

If you are a developer looking to get into the wo...

How to implement gzip compression in nginx to improve website speed

Table of contents Why use gzip compression? nginx...

Solution to overflow:hidden failure in CSS

Cause of failure Today, when I was writing a caro...

Summary of methods to improve mysql count

I believe many programmers are familiar with MySQ...

Docker uses dockerfile to start node.js application

Writing a Dockerfile Taking the directory automat...

The complete process of Docker image creation

Table of contents Preface Creation steps Create a...

Comparing Document Locations

<br />A great blog post by PPK two years ago...