+
80
-

如何将linux下jar包做成 systemctl 服务?

如何将linux下jar包做成 systemctl 服务?

网友回复

+
0
-

1.进入服务配置文件

cd /etc/systemd/system/

2.根据如下操作进行(注意每一步注释)

# 1.创建服务配置文件

vim tool.service

#2.按 i 进入编辑模式把下面内容复制进去

#3.加入下面内容如下

#表示基础信息
[Unit]
#描述
Description=tool-service
#在哪个服务之后启动
After=syslog.target network.target remote-fs.target nss-lookup.target
#表示服务信息
[Service]
Type=simple
User=root
Group=root
#根据自己实际情况写java 环境 jar 包路径 启动配置文件等信息
ExecStart=/usr/java/jdk1.8.0_131/bin/java -jar /opt/tool/tool.jar --spring.profiles.active=pro
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
#安装相关信息
[Install]
WantedBy=multi-user.target

#4. 按esc 键退出编辑模式, 在输入命令 :wq 就保存好了

3:对于systemctl基本常用服务操作

#启动服务

systemctl start tool #或者systemctl start tool.service

#停止服务

systemctl stop tool #或者systemctl stop tool.service

#服务状态

systemctl status tool #或者systemctl status tool.service

#开机启动

systemctl enable tool #或者systemctl enable tool.service

#项目日志

journalctl -u tool #或者journalctl -u tool.service

#开机时禁用服务

systemctl disable tool.service

#查看服务是否开机启动:

systemctl is-enabled app-run.service

#查看已启动的服务列表:

systemctl list-unit-files|grep enabled
我知道答案,我要回答