把spring-boot项目配置为Linux systemd服务,并注册自启动
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
·
把spring-boot项目配置为Linux systemd服务之后,可以方便地使用下面几个命令:
systemctl start myservcie .service
systemctl stop myservcie.service
systemctl restart myservcie.service
systemctl status myservcie.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)
# 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
A beautiful web dashboard for Linux
最近提交(Master分支:3 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)