java 程序配置 systemctl
1.配置service
新建一个service服务文件
sudo vi /etc/systemd/system/demo.service
内容如下
[Unit]
Description=demo server daemon
After=network.target remote-fs.target syslog.target
[Service]
User=usrdbgis
Group=usrdbgis
ExecStart=/usr/local/java/jdk1.8.0_311/bin/java -jar demo-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
WorkingDirectory=/home/program/rest/
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
2.启用服务
# 重新加载服务配置文件
sudo systemctl daemon-reload
# 加入开机自启
sudo systemctl enable demo.service
# 开启服务
sudo systemctl start demo.service
# 关闭服务
sudo systemctl stop demo.service
# 重启服务
sudo systemctl restart demo.service