编写shell脚本检测elasticsearch服务是否正常运行

技术 置顶 精帖
0 542
peng49
peng49 2022-03-18 18:44:32
 

vim 创建 es_check.sh文件

  1. vim es_check.sh

添加如下内容

  1. #! /bin/bash
  2. # 获取状态
  3. status=$(systemctl status elasticsearch | grep Active | awk '{print $2}')
  4. # 判断状态是否是active,如果不是,restart重启服务
  5. if [ $status != 'active' ];then
  6. echo "elasticsearch status is [${status}],strart running "
  7. systemctl restart elasticsearch &
  8. fi

wq保存退出

添加执可执行权限

  1. chmod +x es_check.sh

测试脚本

  1. # 停止服务
  2. systemctl stop elasticsearch
  3. # 执行脚本
  4. ./es_check.sh

输出 elasticsearch status is [xxxx],strart running
表示脚本正常运行

回帖
登录
忘记密码?