centos7下将Springboot添加为系统服务,开机启动

2020-04-22 / 4 阅读 / Java
提示: 此方法是centos7下的配置方法

1、/ets/systemd/system下新建文件 example.service

2、编辑文件内容

[Unit]
Description=example #描述
After=syslog.target network.target  #依赖

[Service]
Type=simple

ExecStart=/usr/bin/java -jar /www/service/example.jar
#前面是java命令的绝对路径  后面是jar包的绝对路径
ExecStop=/bin/kill -15 $MAINPID

User=root
Group=root

[Install]
WantedBy=multi-user.target  #启动等级

3、使用命令

systemctl start example 或  systemctl start example.service

配置改变后:

systemctl daemon-reload
systemctl start sell.service

停止服务:

systemctl stop example 或 systemctl stop example.service

开机启动:

systemctl enable example 或 systemctl enable example.service

禁止开机启动:

systemctl disable example 或  systemctl disable example.service
相关推荐