Current location - Quotes Website - Team slogan - One-click upload of ideajar package how to stop the original jar package
One-click upload of ideajar package how to stop the original jar package
The method of running and stopping jar package under Linux

1 background

After the Java project is developed and the jar package is completed, the jar package needs to be uploaded to Linux to run. If my brother uses Windows, then forget it? (? ω ? )? .

We may think of running jar package through Java-JARPlatform-SCM-V108.jar. The program runs normally, but the window is locked during the running. When we close the window or Ctrl+C interrupts the program, the program will exit. When you stop, you will first find out the process of jar package through PS-ef | grep platform-SCM-v108.jar, and then kill it. This is too complicated. Let's summarize the steps of gracefully starting and stopping jar based on online experience:

2 Linux way to start jar package

2. 1 Simple background startup

Java -jar platform-SCM-v108.jar-spring.profiles.active = product-server.port = 8080 &;

Description:&; It means that the ssh window is not locked when the background is running, but the program will still exit when the window is closed;

2.2 Don't hang up the background startup.

Nohup java -jar platform-SCM-v108.jar-spring.profiles.active = product-server.port = 8080 &;

Note: nohup means to run the command line without hanging up. When the account exits or closes the terminal, the program will still run. When a job is executed with the nohup command, all the output of the job will be redirected to the file nohup.out, unless an output file is specified.

2.3 Don't hang up to start and redirect logs in the background.

nohup Java-jar platform-SCM-v 108 . jar-spring . profiles . active = product-server . port = 8080 & gt; /data/platform/log/platform-scm.txt &;

Description: >/data/platform/log/platform-scm.txtplatform-scm.txt file.

3 stop jar package

3. 1 Simple two steps

Ps -ef | grep platform -scm-v 108.jar

# Find the corresponding process and kill it.

Kill -9 process number

Description: it is divided into two steps, and the operation is cumbersome;

3.2 command stop method

kill-9 ' PS-ef | grep platform-SCM-v 108 . jar | grep-v ' grep ' '

Description: Use the pipeline twice to exclude other processes and directly kill the corresponding process.

4 Online environment script reference

4. 1 Start script

Nohup java -jar platform-SCM-v108.jar-spring.profiles.active = product-server.port = 8080 &;

4.2 Stop the script

kill-9 ' PS-ef | grep platform-SCM-v 108 . jar | grep-v ' grep ' '

4.3 Restart script

kill-9 ' PS-ef | grep platform-SCM-v 108 . jar | grep-v ' grep ' '

Sleep 2

Nohup java -jar platform-SCM-v108.jar-spring.profiles.active = product-server.port = 8080 &;

Sleep 2

Tail closed, over.