基于systemd 的spring boot 应用管理有一个比较方便的能力,就是不用复杂的java 进程处理了,应用发布只需要
进行jar 文件的copy 处理,然后就是服务的重启了systemctl restart <servicename>
应用权限处理
chmod 500 /opt/my-application.jar
参考配置
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
User=myapplication
ExecStart=/opt/my-application.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
说明
以上是一个模式,实际上对于ExecStart 部分也是也可以直接使用<java path > -jar app.jar
注意java 使用绝对路径
同时最好大家的服务都开启开机自启动systemctl enable <appname>.service
[Unit]
Description=mydemo app
After=syslog.target
[Service]
User=root
ExecStart=/usr/bin/java -jar /opt/app.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
参考资料
https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html
https://www.freedesktop.org/software/systemd/man/systemd.service.html
https://www.baeldung.com/spring-boot-app-as-a-service
https://serverfault.com/questions/695849/services-remain-in-failed-state-after-stopped-with-systemctl