背景:原始碼安裝的服務啓動和開機重新啓動都比較麻煩
解決方案:改爲systemctl方式啓動
相關設定:
/usr/lib/systemd/system/*.service
# Systemd unit file for ids
[Unit]
Description=ids
After=syslog.target network.target
[Service]
Type=forking
#定義服務啓動倚賴的java環境
Environment=JAVA_HOME="/TRS/APP/jdk1.8"
#啓動指令碼
ExecStart=/TRS/DEPS/TRSIDS/TRSIDS5.0/bin/startup.sh
#重新啓動指令碼
ExecReload=/TRS/DEPS/TRSIDS/TRSIDS5.0/bin/reload.sh
SuccessExitStatus=143
#停止指令碼
ExecStop=/TRS/DEPS/TRSIDS/TRSIDS5.0/bin/stop.sh
PrivateTmp=true
#啓動使用者
User=root
Group=root
[Install]
WantedBy=multi-user.target
#restart自行研究
systemctl start ids.service
systemctl stop ids.service
systemctl enable ids.service
#startup.sh爲tomcat啓動指令碼
[root@test1 bin]# cat stop.sh
#!/bin/bash
#IDS_PID=`ps aux | grep TRSIDS5.0 | grep -v grep | awk '{print $2}'`
#kill -9 $IDS_PID &> /dev/null
ps aux | grep TRSIDS5.0 | grep -v grep | awk '{print $2}' > /tmp/IDS_PID
for IDS_PID in `cat /tmp/IDS_PID`
do
#kill -9 $IDS_PID &> /dev/null
kill -9 $IDS_PID &> /dev/null
#echo $IDS_PID
done
[root@test1 bin]# cat reload.sh
#!/bin/bash
#測試之後發現這個效果比直接呼叫stop.sh指令碼好
#IDS_PID=`ps aux | grep TRSIDS5.0 | grep -v grep | awk '{print $2}'`
#kill -9 $IDS_PID &> /dev/null
ps aux | grep TRSIDS5.0 | grep -v grep | awk '{print $2}' > /tmp/IDS_PID
for IDS_PID in `cat /tmp/IDS_PID`
do
#kill -9 $IDS_PID &> /dev/null
kill -9 $IDS_PID &> /dev/null
#echo $IDS_PID
done
#bash /TRS/DEPS/TRSIDS/TRSIDS5.0/bin/stop.sh
sleep 1
bash /TRS/DEPS/TRSIDS/TRSIDS5.0/bin/startup.sh &> /dev/null