Elasticsearch 自动重启脚本

#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
export JAVA_HOME=/home/elastic/jdk1.8.0_121
# 获取es进程ID
ES_ID=`ps -ef |grep elasticsearch |grep -w 'elasticsearch-master'|grep -v 'grep'|awk '{print $2}'`
#启动脚本目录
StartES=/root/software/elasticsearch-5.2.2/bin/elasticsearch
# 日志输出
ESMonitorLog=$BIN_DIR/es-master-monitor.log

Monitor()
{
  if [[ $ES_ID ]];then # 这里判断ES进程是否存在
    echo "[info]当前ES进程ID为:$ES_ID"
  else
    echo "[error]ES进程不存在!ES开始自动重启..."
    sh $StartES -d
  fi
}

Monitor>>$ESMonitorLog

cron

*/1 * * * * /bin/sh /home/elastic/es_monitores_monitor.sh