将jar包上传到 你想要的目录下
如 /java/service/demo.jar
进入 /etc/systemd/system 目录下
新建 demo.service
内容如下
----------------------------------------------------
[Unit]
Description=wechat
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/java -jar /java/service/demo.jar
ExecStop=/bin/kill -15 $MAINPID
User=root
Group=root
[Install]
WantedBy=multi-user.target
---------------------------------------------------
systemctl start demo.service 启动服务
systemctl enable 开机自启动
systemctl disable 停止开机自启动
systemctl status 查看状态
systemctl restart 重启服务