#!/bin/bash

pro_dir='/opt/prometheus'
user='prometheus'

ps -ef | grep -w "${pro_dir}/prometheus" | grep -v 'grep' &>/dev/null
if [ $? -eq 0 ];then
  echo "error: prometheus server runing"
  exit 10
fi


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

if [ ! -f "${pro_dir}/prometheus" ];then
  echo "error: prometheus binary file not exist"
  exit 10
fi

cd ${pro_dir}

start_para=`cat ${pro_dir}/script/running_parameters`
value=()

for i in ${start_para};do
  value+=($i)
done

all_value=`echo ${value[*]}`

nohup ${pro_dir}/prometheus \
--config.file=config/prometheus.yml \
${all_value} >> logs/prometheus.log 2>&1 &

sleep 2

ps -ef | grep -w "${pro_dir}/prometheus" | grep -v 'grep' &>/dev/null
if [ $? -eq 0 ];then
  echo "success: prometheus server start"
else
  echo "error: prometheus server start failed"
  exit 10
fi


#--web.config.file=web.yml --web.enable-lifecycle