centos7下systemctl管理springboot微服务的基础配置

来源:互联网 发布:php require once use 编辑:程序博客网 时间:2024/06/05 11:34

一. 关于systemctl的基本命令参考:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html

二. 写service配置,两种方式:设定working目录,springboot会在working目录下寻找application.yml加载;不设定working目录,指定springboot配置文件
2.1 设定working目录:

vi /lib/systemd/system/test.service
[Unit]Description=test [Service]WorkingDirectory=/usr/local/testPrivateTmp=trueRestart=alwaysType=simpleExecStart=/usr/local/java/jdk1.8.0_101/bin/java -jar /usr/local/test/test.jarExecStop=/usr/bin/kill -15  $MAINPID[Install]WantedBy=multi-user.target

2.2 指定springboot配置文件目录

[Unit]Description=test [Service]WorkingDirectory=/usr/local/testPrivateTmp=trueRestart=alwaysType=simpleExecStart=/usr/local/java/jdk1.8.0_101/bin/java -jar /usr/local/test/test.jar --spring.config.location=/usr/local/test/application.ymlExecStop=/usr/bin/kill -15  $MAINPID[Install]WantedBy=multi-user.target

三. systemctl 管理,让配置生效。若是修改配置文件,需要reload:

sudo systemctl daemon-reload
sudo systemctl enable test.service

启动服务

systemctl start test

systemd官方文档: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html

阅读全文
1 0
原创粉丝点击