SpringBoot 应用配置 CentOS 服务化

Scroll Down

1.配置 service

vi /etc/systemd/system/xxx.service

内容基本格式如下:

[Unit]
Description=SpringBoot
#Requires=docker.service
#After=docker.service
After=syslog.target

[Service]
User=root
ExecStart=/opt/java/jdk1.8.0_191/bin/java -server -Xms192m -Xmx192m -Xmn64m -Xss256k -XX:SurvivorRatio=6 -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+PrintClassHistogram -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Xloggc:log/gc.log -jar /xxx/xxx-1.0.0.jar --spring.profiles.active=prod
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
SuccessExitStatus=143
Restart=1

[Install]
WantedBy=multi-user.target

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

2.使配置生效

# 重载系统服务
systemctl daemon-reload
# 使服务 xxx 能够开机启动
systemctl enable xxx
# 启动
systemctl start xxx
# 停止
systemctl stop xxx
# 重启
systemctl restart xxx
# 项目日志
journalctl -u APP/APP.service

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