“This is the 20th day of my participation in the First Challenge 2022. For details: First Challenge 2022”
preface
SpringBoot is a popular open source lightweight framework of Java language in recent years. It is simple, convenient and easy to learn, and is used by many Java developers. This article will briefly introduce the Linux nohUP command and the NohUP startup method of SpringBoot project in Linux system.
Nohup introduction
Nohup (No hang up) is mainly used to run commands in the background of the system without hanging up. After exiting the terminal, it will not affect the running of the program. In this way, the service can be run in the foreground without the console being open all the time.
After the nohup command is executed, a file named nobup.out is output by default.
The syntax of the nohup command is:
Nohup Command [Arg...] [&]Copy the code
Parameter description of the nohup command:
- Command: indicates the Command that needs to be suspended in the background.
- Arg: Parameters that specify the output file and associated path.
- & : Allows commands to be executed in the background and continue to be executed after the terminal exits.
SpringBoot start
One jar package startup command that can be executed in Java is:
java -jar demo.jar
Copy the code
The Command java-jar demo.jar is the Command in the nohup Command, which needs to be suspended. In the Linux server, we find the JAR package file we need to execute. Then enter the following suspended commands in the format:
nohup java -jar demo-server.jar &
Copy the code
Nohup: Ignoring input and appending output to ‘nohup.out’. Ignore the console output logs after the suspension and print the output logs to the nohup.out file. The following figure shows the command output:Run the tail -f nohup. Out command to query logs. You can view that the Demo-server service is started.
tail -f nohup.out
Copy the code
Viewing the project startup process, you can see that the Demo-server project has been started. The start-up projects are as follows.
ps -ef |grep demo-server.jar
Copy the code
To stop the demo-Server service in the background, stop it directly. Run the following command:
kill -9Pid process,Copy the code
After the kill -9 command is executed, the Demo-server service is stopped.
conclusion
Ok, the above is the Linux system nohup command introduction and SpringBoot project in Linux system nohup start, thank you for reading, I hope you like, if you are helpful, welcome to like the collection. If there are shortcomings, welcome comments and corrections. See you next time.
About the author: [Little Ajie] a love tinkering with the program ape, JAVA developers and enthusiasts. Public number [Java full stack architect] maintainer, welcome to pay attention to reading communication.