把spring-boot项目配置为Linux systemd服务之后,可以方便地使用下面几个命令:
systemctl start
myservcie
.service
systemctl stopmyservcie.service
systemctl restartmyservcie.service
systemctl statusmyservcie.service
或这些:
service myservice status
service myservice start
service myservice stop
service myservice restart
1、开始配置:
vi /usr/lib/systemd/system/user-service.service
[Unit]
Description=My Service
After=syslog.target
[Service]
ExecStart=/usr/java/default/bin/java -jar /opt/app/spring-boot/myservice.jar --spring.profiles.active=dev
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target其中,ExecStart可以加上其他参数,比如:
/usr/java/default/bin/java -jar -Xms256m -Xmx4G -Dlog.level.console=warn -Dlog.level.ysb=info /opt/app/spring-boot/myservice.jar --spring.profiles.active=prod另外,143是spring-boot服务被stop的时候的status code:
# service myservice stop
# service myservice status
myservice.service - My Service
Loaded: loaded (/usr/lib/systemd/system/myservice.service; enabled)
Active: inactive (dead) since Tue 2016-11-29 14:21:19 CST; 1s ago
Process: 19146 ExecStart=/usr/java/default/bin/java -jar /opt/app/spring-boot/myservice.jar --spring.profiles.active=dev
(code=exited, status=143)
Main PID: 19146 (code=exited, status=143)
如果不加上SuccessExitStatus=143,stop服务的时候会变成failed状态,而不是inactive状态。
2、注册开机自启动:
systemctl enable
myservice
.service
如果修改服务配置文件,需要执行:
systemctl daemon-reload
3、查看该服务的console log:
journalctl -u myservice.service
journalctl -f -u myservice.service