ES節(jié)點的自動重啟邏輯:
#!/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
# 第二次仍檢測到應用宕機后,啟動應用邏輯
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
# 啟動應用后檢測是否啟動成功邏輯
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ù)平臺ES節(jié)點$insName 自動重啟成功" "$now 數(shù)據(jù)平臺ES節(jié)點$insName 系統(tǒng)檢測到宕機,現(xiàn)已重啟成功"
else
echo "$now $insName has been restarted, but the restart failed. Please check manually." | tee -a $log
#send_mail "數(shù)據(jù)平臺ES節(jié)點$insName 自動重啟失敗" "$now 數(shù)據(jù)平臺ES節(jié)點$insName 系統(tǒng)檢測到宕機,已嘗試重啟,但重啟失敗,請人工檢查原因."
fi
fi
fi
}
main(){
check_es ins004 30109 &
check_es ins005 30110 &
check_es ins006 30111 &
wait
}
main
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。