#!/bin/bash

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

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

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

kill -9 $pid
sleep 2

ps -ef | grep -w "${grafana_dir}/bin/grafana" | grep -v 'grep' &>/dev/null
if [ $? -ne 0 ];then
  echo "success: grafana process exit"
else
  echo "error: !!!grafana process exit failed!!!"
  exit 10
fi



