1. 使用systemd优雅启停应用
-
添加依赖
pom.xm的build.plugins节点<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin>
-
添加服务
/etc/systemd/system/myapp.service[Unit] Description=myapp After=syslog.target [Service] User=root ExecStart=/var/myapp/myapp.jar SuccessExitStatus=143 [Install] WantedBy=multi-user.target
-
配置 在jar包同目录下增加同名配置文件
myapp.confJAVA_OPTS="-server -Xms100m -Xmx300m -Xmn128m -Xss256k"
-
启停
systemctl enable myapp # 开机自启动 systemctl status|start|stop|restart myapp journalctl -u myapp # 看日志,shift+g跳转到最后一行