spring boot 應(yīng)用 systemd 管理簡單說明
基于systemd 的spring boot 應(yīng)用管理有一個比較方便的能力,就是不用復(fù)雜的java 進程處理了,應(yīng)用發(fā)布只需要
進行jar 文件的copy 處理,然后就是服務(wù)的重啟了systemctl restart <servicename>
應(yīng)用權(quán)限處理
?
chmod 500 /opt/my-application.jar
參考配置
[Unit]Description=A Spring Boot applicationAfter=syslog.target[Service]User=myapplicationExecStart=/opt/my-application.jarSuccessExitStatus=143Restart=alwaysRestartSec=5[Install]WantedBy=multi-user.target
說明
以上是一個模式,實際上對于ExecStart 部分也是也可以直接使用<java path > -jar app.jar
?注意java 使用絕對路徑
同時最好大家的服務(wù)都開啟開機自啟動systemctl enable <appname>.service
?
[Unit]Description=mydemo appAfter=syslog.target
?
[Service]User=rootExecStart=/usr/bin/java -jar /opt/app.jarSuccessExitStatus=143Restart=alwaysRestartSec=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
https://www.dianjilingqu.com/616267.html