<>Spring Boot Detailed explanation of three startup modes and backstage operation of the project

<>1 Spring Boot Three ways to start a project

* function Application.java In class Main method
* Project management tool launch
* Maven project :mvn spring-boot:run
* Gradle project :gradle run
* Packed into Jar File start :java -jar [ entry name ].jar
* Maven project :mvn package, stay Target Generate under directory Jar package
* Gradle project :gradle build, stay build/libs Generate under directory Jar package
<>2 Spring Boot Project background start

In the project development stage , The first two methods are usually used to start , The third method is usually used in deployment

however java -jar [ entry name ].jar Command can only run items in the foreground , When performing other operations or shutting down SSH In conversation , Termination of project operation

<>2.1 Installation configuration nohup command

nohup effect : Make the program execute in the server background , The command to execute the program does not depend on ssh Interface .
usage :nohup Command to be executed &

* query nohup Whether to install which nohup # see /usr/bin Is there any in the catalog nohup command
* Download and install nohup yum install coreutils
* Find downloaded nohup cd /usr/bin which nohup
* to configure nohup route vi ~/.bash_profile # .bash_profile # Get the aliases and
functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment
and startup programs PATH=$PATH:$HOME/bin PATH=$PATH:/usr/bin export PATH
* Immediate configuration source ~/.bash_profile
* use nohup command nohup [ Commands that need to be executed in the background ] &
<>2.2 nohup command

* purpose : Run command without hanging up
* grammar :nohup command [Arg...] [&]
* describe :nohup Command is executed by Command Commands and their parameters [Arg…] form , Ignore all hangs (SIGHUP) signal .
* Example :nohup java -jar xxx.jar &
nohup The log in the execution result will be output to the nohup.out In file , Usually, we can use the above command .
nohup java -jar xxx.jar > catalina.out 2>&1 & # Specify the log file output address nohup java -jar
xxx.jar >/dev/null & # Turn off log output
<>2.3 Hang up nohup command
ps -ef # View system processes , And write it down java -jar xxx.jar Ordered PID kill -9 [PID] # Force end process
<>3 App launch , stop it , restart shell script

* Script to launch app :start.sh #!/bin/bash nohup java -jar yourapp.jar --server.port=8888
&
* Close script for app :stop.sh #!/bin/bash PID=$(ps -ef | grep yourapp.jar | grep -v grep
| awk '{ print $2 }') if [ -z "$PID" ] then echo Application is already stopped
else echo kill $PID kill $PID fi
* Integrated shutdown and startup scripts :run.sh, Because the application will be closed first , Then launch the app , This will not cause port conflicts and other problems , Suitable for repeated calls in continuous integration system .
#!/bin/bash echo stop application source stop.sh echo start application source
start.sh
<>4 Create system service

stay Spring Boot Of Maven Plug in , It also provides the ability to build a complete executable , What do you mean ? That is to say , We don't have to java
-jar, But directly jar To execute the program . In this way, we can easily create a system service to run in the background .

* stay pom.xml Add to Spring Boot Plug in for , And pay attention to the settings executable to configure <build> <plugins> <plugin> <
groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin
</artifactId> <configuration> <executable>true</executable> </configuration> </
plugin> </plugins> </build>
* After completing the above configuration , use mvn install Packing , Build an executable jar package
* Create a soft connection to /etc/init.d/ Directory sudo ln -s /var/yourapp/yourapp.jar
/etc/init.d/yourapp
* After soft connection creation , So we can use the following command yourapp.jar Apply to control startup , stop it , Restart operation /etc/init.d/yourapp
start|stop|restart

Technology
©2019-2020 Toolsou All rights reserved,
The shortest path of maze BFS algorithm (python realization ) Cheats developers apologize Redis Counter High concurrency applications c Language rose advertising code TypeScript Data types in is enough inherit jpa Repository Write custom method query @Repository The role of annotations golang One line of code converts the slice into a semicolon separated string be based on STM32 Design of infrared obstacle avoidance car ( There is a code ) subversion ! Never take a nap longer than this time ! Watch out for fatal diseases …