本地有一个query.jar 现通过脚本注册为服务实现自启动
1.编写启动脚本query-service.sh服务
#!/bin/sh
#export JAVA_HOME=/usr/local/jdk1.8.0_131
#export PATH=$JAVA_HOME/bin:$PATH
java -jar /home/yxy-wg/server03/query.jar > /home/yxy-wg/server03/logs/query.log &
echo $! > /var/run/query-service.pid
2.编写停止脚本
#!/bin/sh
PID=$(cat /var/run/query-service.pid)
kill -9 $PID
3.编写注册服务
在/usr/lib/systemd/system下编写query-service脚本
[root@iz2ze0fq2isg8vphkpos5sz shell]# cd /usr/lib/systemd/system
[root@iz2ze0fq2isg8vphkpos5sz system]# more query-service .service
[Unit]
Description=query-service for yxy-gw
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/home/yxy-wg/server03/query-service.sh
ExecStop=/home/yxy-wg/server03/query-service-stop.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4.增加可执行权限
[root@localhost server03]# chmod +x query-service.sh query-service-stop.sh
5.服务操作命令
systemctl enable query-service #开机自启动
systemctl stop query-service #停止
system start query-service #启动