Java jar包部署为linux 服务

1:新建一个服务
vim /etc/systemd/system/quote.service

2:编写脚本

[Unit]
Description=Service for quote
Documentation=https://www.xindaowm.com
After=network.target
	
[Service]
User=nobody
#Type=forking
PIDFile=/run/quote.pid
ExecStart=/bin/sh -c '/usr/local/jdk1.7.0_80/bin/java -jar /usr/local/src/quote/quote.jar >> /var/log/quote.log 2>&1'
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
	
[Install]
WantedBy=multi-user.target

3:新建一个日志文件
vim /var/log/quote.log
改变文件或目录的所有者
chown nobody /var/log/quote.log
改变文件或目录的所属组
chgrp nobody /var/log/quote.log


4:启动服务
systemctl start quote 

5:关闭服务
systemctl stop quote

6:查看服务状态
systemctl status quote -l

7:加入开机自启

systemctl enable quote.service


查看console log
journalctl -u quote.service
journalctl -f -u quote.service

 

你可能感兴趣的:(linux,java,jar,linux服务)