2. 在本地编写服务启停的脚本
2.1 服务启动
2.1.1 创建脚本文件
# 脚本可在任意位置
touch notice-service-start
chmod 755 notice-service-start
编辑脚本
#!/bin/sh
echo start notice service
# cd /data/soft/analysisNotice
# run jar
nohup java -Xms128m -Xmx512M -jar /data/soft/analysisNotice/analysisNoticeWX.jar --spring.config.location=/data/soft/analysisNotice/config/ >/dev/null &
# record pid
echo $! > /var/run/notice-service.pid
2.2 服务停止
touch notice-service-stop
chmod 755 notice-service-stop
编辑脚本
#!/bin/sh
PID=$(cat /var/run/notice-service.pid)
kill -9 $PID
编写服务脚本
在/etc/systemd/system 下 编写 notice.service 脚本
[Unit]
Description=notice-service
After=syslog.target
[Service]
Type=forking
ExecStart=/data/soft/analysisNotice/notice-service-start
ExecStop=/data/soft/analysisNotice/notice-service-stop
PrivateTmp=true
#是否重启
Restart=always
#重启时间(秒)
RestartSec=60
[Install]
WantedBy=multi-user.target
服务启停
systemctl enable notice.service 开机自启动
systemctl start notice.service 启动
systemctl stop notice.service 停止
systemctl status notice.service 查看状态