1.進入到系統(tǒng)服務文件夾下:cd /etc/systemd/system
2.創(chuàng)建服務文件:vim xxx.service
[Unit]
Description=XXX Service
After=network.target
[Service]
Type=simple
ExecStart=/home? java -jar /home/xxx.jar /home/xxx_log.conf
WorkingDirectory=/home
User=root
Group=root
StandardOutput=null
StandardError=/home/error.log
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
說明:(Restart 是否開啟重啟,RestartSec 3秒后再次嘗試啟動)
3.生效配置
1.sudo systemctl daemon-reload?# 重新加載 Systemd 配置
2.sudo systemctl?enable xxx.service?# 設(shè)置服務開機自啟動
3.sudo systemctl start xxx.service?# 啟動服務