cd /usr/lib/systemd/system
# 创建一个demo.service
touch demo.service
# 编辑
vim demo.service
修改jar路径,复制到demo.service中
[Unit]
# 描述 需修改
Description=demo.service
After=syslog.target network.target
[Service]
Type=simple
# jar路径 需修改
ExecStart=/usr/bin/java -jar /usr/local/demo.jar
ExecStop=/bin/kill -15 $MAINPID
User=root
Group=root
[Install]
WantedBy=multi-user.target
# 重新加载
systemctl daemon-reload
# 启动
systemctl start demo
# 重启
systemctl restart demo
# 停止
systemctl stop demo
# 状态
systemctl status demo