實驗環境
1.上傳或從Nexus上拉取可運行的springboot項目包
java -jar /opt/myapp.service
2.配置nginx.service
2.1編輯/etc/systemd/system/myapp.service
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
Type=forking
User=root
ExecStart=/usr/bin/java -jar /opt/estest.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3. 常見操作
3.1 刷新systemd服務
systemctl daemon-reload
3.2 查看所有已啟動的服務
systemctl list-units --type=service
3.3 啟動、停止、重啟服務
systemctl start myapp.service
systemctl stop myapp.service
systemctl restart myapp.service
3.4 開啟/關閉開機自啟動
systemctl enable myapp.service
systemctl disable myapp.service