12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/bin/bash
- set +u
- set -e
- # set -x
- base_dir=$(
- cd "$(dirname "$0")"
- pwd
- )
- cd $base_dir
- # ./auto_del_log.sh
- function log_warn() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[WARN] $date $1" | tee -a "./log/run_log"
- }
- function log_info() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[INFO] $date $1" | tee -a "./log/run_log"
- }
- function log_err() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[ERROR] $date $1" | tee -a "./log/run_log"
- }
- grafana_log_path="./log/"
- # node_exporter section
- if ps -auxc | grep "grafana" | grep -v grep > /dev/null; then
- log_info "grafana 已在运行"
- elif [[ ! -f "./grafana" ]]; then
- log_info "no grafana found, skip"
- else
- if [[ ! -d $grafana_log_path ]]; then
- mkdir "$grafana_log_path"
- fi
- grafana_log_file="grafana_$(date "+%Y-%m-%d-%H:%M:%S").log"
- ./grafana &>> "${grafana_log_path}${grafana_log_file}" &
- sleep 1
- if grep -E 'cannot|not defined|License does not exist' "${grafana_log_path}${grafana_log_file}" >> /dev/null; then
- log_err "grafana 启动遇到问题,请检查${grafana_log_file}"
- else
- log_info "grafana 启动成功!"
- fi
- fi
|