run.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. set +u
  3. set -e
  4. # set -x
  5. base_dir=$(
  6. cd "$(dirname "$0")"
  7. pwd
  8. )
  9. cd $base_dir
  10. # ./auto_del_log.sh
  11. function log_warn() {
  12. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  13. local para=$1
  14. echo "[WARN] $date $1" | tee -a "./log/run_log"
  15. }
  16. function log_info() {
  17. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  18. local para=$1
  19. echo "[INFO] $date $1" | tee -a "./log/run_log"
  20. }
  21. function log_err() {
  22. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  23. local para=$1
  24. echo "[ERROR] $date $1" | tee -a "./log/run_log"
  25. }
  26. grafana_log_path="./log/"
  27. # node_exporter section
  28. if ps -auxc | grep "grafana" | grep -v grep > /dev/null; then
  29. log_info "grafana 已在运行"
  30. elif [[ ! -f "./grafana" ]]; then
  31. log_info "no grafana found, skip"
  32. else
  33. if [[ ! -d $grafana_log_path ]]; then
  34. mkdir "$grafana_log_path"
  35. fi
  36. grafana_log_file="grafana_$(date "+%Y-%m-%d-%H:%M:%S").log"
  37. ./grafana &>> "${grafana_log_path}${grafana_log_file}" &
  38. sleep 1
  39. if grep -E 'cannot|not defined|License does not exist' "${grafana_log_path}${grafana_log_file}" >> /dev/null; then
  40. log_err "grafana 启动遇到问题,请检查${grafana_log_file}"
  41. else
  42. log_info "grafana 启动成功!"
  43. fi
  44. fi