CentOS系统运行jar添加到系统服务并设置开机自启

CentOS系统运行jar添加到系统服务并设置开机自启,第1张

写在前面:在实际工作,我们经常会在linux上运行Spring boot编写的微服务程序,方便使用经常打包的jar格式,有时候会重启系统,所以我们会想到将运行jar文件的 *** 作添加到系统服务并开机自启。

废话不多数,直接开干!

1.新增service配置文件

vi /etc/systemd/system/hello.service

文件内容:

[Unit]
Description=hellow java service
[Service]
WorkingDirectory=/usr/local/jar/
PrivateTmp=true
Restart=always
Type=simple
ExecStart=/usr/java/jdk1.8.0_231-amd64/bin/java -Xmx1024m -Xms512m -Xss256k -jar /usr/local/jar/hello.jar
ExecStop=/usr/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

部分参数配置详解
Description=  #要设置的服务名
WorkingDirectory=    #jar存放的位置
ExecStart=  #执行命令+ jar文件的绝对路径
ExecStop= #停止 *** 作 

2.重新载入systemd

systemctl daemon-reload

.查看服务状态

systemctl status hello             #服务名

5.其他常用命令

systemctl start hello        #启动服务
systemctl stop hello        #停止服务
systemctl reload hello        #重新加载

6.设置开机自启

systemctl enable hello

7.取消开机自启

systemctl disable hello

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/928880.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-17
下一篇 2022-05-17

发表评论

登录后才能评论

评论列表(0条)

保存