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

背景说明

最近监控到新安装的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 语句去掉;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值