#!/bin/bash


script_dir=$(dirname "$(readlink -f "$0")")
alert_dir=$(dirname "$script_dir")
user='alertmanager'
log_dir="logs/alertmanager.log"

pid=`ps -ef | grep -w "${alert_dir}/alertmanager" | grep -v grep | awk '{print $2}'`
if [ ! -n "$pid" ];then
  echo "error: !!!Alertmanager server not running!!!"
  exit 10
fi

if [ "`whoami`" != "${user}" ];then
  echo "error: !!!Excute user not ${user}!!!"
  exit 10
fi

kill $pid
sleep 2
ps -ef | grep -w "${alert_dir}/alertmanager" | grep -v grep &>/dev/null
if [ $? -ne 0 ];then
  echo "success: !!!Alertmanager process exit!!!"
else
  echo "error: !!!Alertmanager process exit failed!!!"
  exit 10
fi



