把Jar包应用加入到Linux系统服务中

把Jar包应用加入到Linux系统服务中

1、配置启动脚本:start.sh和service.sh

#!/bin/bash
  export LD_LIBRARY_PATH=/home/cg/xxx/lib
  nohup /home/java64/jdk1.8.0_221/bin/java -jar /home/cg/xxx-2.0.24.b.jar >/dev/null 2>&1 &

2、写系统服务,例如:ess_gc.service

[Unit]
Description=ess_gc
After=network.target

[Service]
Type=forking
Restart=on-failure
ExecStart=/home/cg/xxx/service.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3、启动系统服务

1.#确认service.sh脚本中的java路径
/home/java64/jdk1.8.0_221/bin/java  需要改成java对应路径

2.#复制ess_gc.service到/usr/lib/systemd/system中
cp ess_gc.service /usr/lib/systemd/system/

3.#启动ess_gc.service并设置开机自启
$ systemctl enable ess_gc.service 


[root@loaclhost system]#  systemctl enable ess_gc.service
Created symlink from /etc/systemd/system/multi-user.target.wants/ess_gc.service to /usr/lib/systemd/system/ess_gc.service.


4.#启动服务
$ systemctl start ess_gc.service
[root@loaclhost system]# systemctl start ess_gc.service

5.#检查服务状态
$ systemctl status ess_gc.service

6.#停止服务
$ systemctl stop ess_gc.service

猜你喜欢

转载自blog.csdn.net/fen_fen/article/details/134879221