Spring Boot 優(yōu)雅停止服務(wù)
點(diǎn)擊上方藍(lán)色字體,選擇“標(biāo)星公眾號(hào)”
優(yōu)質(zhì)文章,第一時(shí)間送達(dá)
76套java從入門到精通實(shí)戰(zhàn)課程分享
1、基礎(chǔ)知識(shí)
2、測(cè)試
2.1、新建測(cè)試項(xiàng)目
2.1.1、環(huán)境信息
2.1.2、新建 SpringBoot 項(xiàng)目
2.2、打包
2.3、部署
2.3.1、環(huán)境信息
2.3.2、手動(dòng)優(yōu)雅停止服務(wù)
[root@test test]# nohup java -jar ./demo-0.0.1-SNAPSHOT.jar > ./logs/stdout.log 2>&1 &
[1] 1679
[root@test test]# ps -ef|grep demo-0.0.1-SNAPSHOT.jar
root 1679 20331 99 23:36 pts/0 00:00:12 java -jar ./demo-0.0.1-SNAPSHOT.jar
root 1729 20331 0 23:36 pts/0 00:00:00 grep --color=auto demo-0.0.1-SNAPSHOT.jar
[root@test test]# kill 1679
[root@test test]# more logs/stdout.log
nohup: ignoring input
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.7.RELEASE)
2021-05-13 23:36:31.536 INFO 1679 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on 196-Pure-CentOS7 with PID 1679 (/root/test/demo-0.0.1-SNAPSHOT.jar started by root in /root/test)
2021-05-13 23:36:31.541 INFO 1679 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-05-13 23:36:32.807 INFO 1679 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-13 23:36:32.825 INFO 1679 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-13 23:36:32.825 INFO 1679 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-05-13 23:36:32.917 INFO 1679 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-13 23:36:32.918 INFO 1679 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1285 ms
2021-05-13 23:36:33.171 INFO 1679 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-13 23:36:33.388 INFO 1679 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-13 23:36:33.404 INFO 1679 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.59 seconds (JVM running for 3.289)
2021-05-13 23:40:40.481 INFO 1679 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2.3.3、腳本退出
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
// generate a pid in a specified path, while use command to shutdown pid : cat ./app.pid | xargs kill
SpringApplication application = new SpringApplication(DemoApplication.class);
application.addListeners(new ApplicationPidFileWriter("./app.pid"));
application.run();
}
}
#!/bin/bash
# Program:
# This program for start java services.
# History:
# 2021/05/12 First release
# PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# export PATH
# start javar services
nohup java -jar ./demo-0.0.1-SNAPSHOT.jar > ./logs/stdout.log 2>&1 &
exit 0
#!/bin/bash
# Program:
# This program for stop java services.
# History:
# 2021/05/12 First release
# PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# export PATH
# service : java
cat ./app.pid | xargs kill
exit 0
3、總結(jié)
版權(quán)聲明:本文為博主原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接和本聲明。
本文鏈接:
https://blog.csdn.net/achi010/article/details/116770240
粉絲福利:Java從入門到入土學(xué)習(xí)路線圖
??????

??長(zhǎng)按上方微信二維碼 2 秒
感謝點(diǎn)贊支持下哈 
評(píng)論
圖片
表情




