ES節(jié)點(diǎn)的自動(dòng)重啟邏輯:
#!/bin/bash
log="/home/srvop/es_restart.log"
send_mail(){
to_receiver=""
subject=$1
mailbody=$2
curl -H "Content-type: application/json;charset=utf-8" -X POST -d '{"to_receiver": $to_receiver, "subject": $subject, "mailbody": $mailbody}' http://ip:port/login
}
check_es(){
insName=$1
port=$2
ps aux | grep $insName | grep -v grep > /dev/null ; proc_status=`echo $?`
netstat -ntlp | grep $port | grep -v grep > /dev/null ; port_status=`echo $?`
if [[ $proc_status -ne 0 || $port_status -ne 0 ]]; then
now=`env LANG=en_US.UTF-8 date +"%Y-%m-%d %H:%M:%S"`
echo "$now $insName process or $port port non-existent,check again." | tee -a $log
sleep 10
# 第一次判斷檢測失敗后再次檢測邏輯
ps aux | grep $insName | grep -v grep > /dev/null ; proc_status=`echo $?`
netstat -ntlp | grep $port | grep -v grep > /dev/null ; port_status=`echo $?`
if [[ $proc_status -ne 0 && $port_status -ne 0 ]]; then
# 第二次仍檢測到應(yīng)用宕機(jī)后,啟動(dòng)應(yīng)用邏輯
now=`env LANG=en_US.UTF-8 date +"%Y-%m-%d %H:%M:%S"`
echo "$now $insName process and $port port non-existent,and restart proc now." | tee -a $log
cd /srvop/apache/servers/szsc-smt-es-prd-$insName/bin/ ; ./elasticsearch -d
#cd /srvop/apache/servers/szsc-smt-es-prd-$insName/bin/ ; touch $insName.txt
now=`env LANG=en_US.UTF-8 date +"%Y-%m-%d %H:%M:%S"`
echo "$now $insName has been restarted." | tee -a $log
sleep 120
# 啟動(dòng)應(yīng)用后檢測是否啟動(dòng)成功邏輯
ps aux | grep $insName | grep -v grep > /dev/null ; proc_status=`echo $?`
netstat -ntlp | grep $port | grep -v grep > /dev/null ; port_status=`echo $?`
now=`env LANG=en_US.UTF-8 date +"%Y-%m-%d %H:%M:%S"`
if [[ $proc_status -eq 0 && $port_status -eq 0 ]]; then
echo "$now $insName has been restarted successfully." | tee -a $log
#send_mail "數(shù)據(jù)平臺(tái)ES節(jié)點(diǎn)$insName 自動(dòng)重啟成功" "$now 數(shù)據(jù)平臺(tái)ES節(jié)點(diǎn)$insName 系統(tǒng)檢測到宕機(jī),現(xiàn)已重啟成功"
else
echo "$now $insName has been restarted, but the restart failed. Please check manually." | tee -a $log
#send_mail "數(shù)據(jù)平臺(tái)ES節(jié)點(diǎn)$insName 自動(dòng)重啟失敗" "$now 數(shù)據(jù)平臺(tái)ES節(jié)點(diǎn)$insName 系統(tǒng)檢測到宕機(jī)象对,已嘗試重啟,但重啟失敗烟具,請(qǐng)人工檢查原因."
fi
fi
fi
}
main(){
check_es ins004 30109 &
check_es ins005 30110 &
check_es ins006 30111 &
wait
}
main
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者