Shell Daemon程序监控宕掉的ES-HEAD插件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuwei0376/article/details/84108917

背景说明

最近监控到新安装的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相关获取任务进程号方法

[es_deployman@balabala-50 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

[es_deployman@balabala-50 elasticsearch-head]$ ps -ef|grep grunt|grep -v grep|awk -F ‘\s+’ ‘{print $1}’
es_depl+

[es_deployman@balabala-50 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 语句去掉;

猜你喜欢

转载自blog.csdn.net/liuwei0376/article/details/84108917