Shell Daemon程式監控宕掉的ES-HEAD外掛
阿新 • • 發佈:2019-01-01
背景說明
最近監控到新安裝的es叢集的head服務經常掛掉,導致http://ip:9100 UI頁面打不開。
檢查了es叢集沒有問題,卻發現啟動head的npm grunt服務異常掛掉(es高版本後,預設使用npm的grunt服務啟動web服務),查詢了下日誌暫未發現任何問題,於是打算寫一個grunt服務異常故障重啟shell指令碼臨時過渡一下。
相關程式碼
es_head_self_restart.sh
#!/bin/sh # Author: angelfish # Desc: a daemon program for pull and restart the downed ES-HEAD plugin. curr_time=$(date "+%Y-%m-%d %H:%M:%S") start_command='/usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server &' while : echo '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Current time is: '$curr_time do curr_time=$(date "+%Y-%m-%d %H:%M:%S") echo ">> Current path is: " $PWD runningStatus=$(ps -ef|grep "grunt"|grep -v "grep") if [ "$runningStatus" ]; then echo "Npm grunt server for es-head plugin was already started" echo "here we do nothing" echo '************************* $runningStatus : '$runningStatus else echo "Detected that grunt server was down, will attempt start it again." #$start_command /usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server & fi sleep 30 done
grep + awk相關獲取任務程序號方法
[[email protected] elasticsearch-head]$ ps -ef|grep grunt|grep -v grep|awk -F ‘\s+’ ‘{print $0}’
es_depl+ 12954 12946 0 12:04 pts/0 00:00:01 grunt
[[email protected] elasticsearch-head]$ ps -ef|grep grunt|grep -v grep|awk -F ‘\s+’ ‘{print $1}’
es_depl+
[
[email protected] elasticsearch-head]$ ps -ef|grep grunt|grep -v grep|awk -F ‘\s+’ ‘{print $2}’
12954
一些想法
關於啟動方式:
1、可以以nohup方式啟動該daemon指令碼,如下:nohup es_head_self_restart.sh >> es_head_self_restart.sh.out &
2、crontab方式方式啟動定期檢查狀態,這時可將shell 腳本里的sleep 語句去掉;