SpringBoot 应用配置服务化

# Linux  /  CentOS  /  SpringBoot  /  CentOS7

1.配置 service

vi /etc/systemd/system/xxx.service

内容基本格式如下:

[Unit]
Description=SpringBoot
After=syslog.target

[Service]
User=root
ExecStart=/opt/java/jdk1.8.0_162/bin/java -server -Xms256m -Xmx256m -jar /opt/xxx/xxx-latest.jar
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

注意:ExecStart 中可执行命令和文件路径都需要是绝对路径

2.使配置生效

# 重载系统服务
systemctl daemon-reload
# 使服务 xxx 能够开机启动
systemctl enable xxx
# 启动
systemctl start xxx
# 停止
systemctl stop xxx
# 重启
systemctl restart xxx

进一步配置可参考:CentOS7使用systemctl添加自定义服务

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×