(The method in this blog post is applicable to both Alibaba Cloud and Tencent and servers)
Scenes:
Deploy a backend program (climate-0.0.1-SNAPSHOT.jar) to my Tencent Cloud server. The general startup command is as follows:
java -jar climate-0.0.1-SNAPSHOT.jar
The above figure shows that the project is successfully deployed and can be accessed on the browser
But after the terminal is closed, it cannot be accessed, and the online effect cannot be achieved.
And we want the project program to continue to run after closing and exiting the terminal.
At this time, you need to use the nohup command to start (this command can continue to run the corresponding process after you log out of the account/close the terminal)
Enter the following command:
nohup java -jar climate-0.0.1-SNAPSHOT.jar
But it will report an error (meaning: when executing the nohup command, there will often be an error of not having write permission)
1. Reason
It is because the use of nohup will generate a log file, which is written to nohup.out by default
2. Solve
Output the log of nohup to /dev/null, this directory will make all the information to it disappear automatically
nohup java -jar climate-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null &
Other solutions:
Just add an & at the end to run directly in the background
nohup java -jar climate-0.0.1-SNAPSHOT.jar &
stop process
If you want to stop the process running, you can kill it by command (kill -9 process number PID) process number
You can also use the ps -def | grep "process name" command to find the PID.
Once the PID is found, it can be removed with kill PID.
kill -9 进程号PID
If it is found that at startup, check the log and find that the port number is occupied
Use lsof -i:[port number] to view the process using a certain port
lsof -i:[端口号]
Then use kill to kill the city and start it again
Terminate processes running in the background
kill -9 进程号PID
For example: found that port 6868 is occupied