linux 可运行jar注册为服务

一、编写jar启动执行的脚本(创建脚本)

1 cd /home/sso/service
2 vim sso-start.sh

 

启动脚本(填入脚本内容):

1 #!/bin/sh
2  
3 nohup /usr/local/java/jdk1.8.0_171/bin/java -jar  /home/sso/jar/sso.jar >  /home/sso/jar/sso.log &
4 echo $! > /var/run/sso.pid

 

二、编写jar停止执行的脚本(创建脚本)

1 cd /home/sso/service
2 vim sso-stop.sh

停止脚本(填入脚本内容)

1 #!/bin/bash
2 PID=$(cat /var/run/sso.pid)
3 kill -9 $PID

 

三、在/usr/lib/systemd/system 下编写开机自启脚本(创建脚本)

1 cd /usr/lib/systemd/system
2 vim sso.service

自启脚本(填入脚本内容)

 1 [Unit]
 2 Description=sso_service
 3 After=syslog.target network.target
 4  
 5 [Service]
 6 Type=forking
 7 ExecStart=/home/sso/service/sso-start.sh
 8 ExecStop=/home/sso/service/sso-stop.sh
 9 PrivateTmp=true
10  
11 [Install]
12 WantedBy=multi-user.target

 

四、启动、停止、开机自启动

systemctl start/stop/enable sso

 

posted @ 2021-01-31 21:13  追逐丶  阅读(203)  评论(0编辑  收藏  举报