run.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env 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. log_path="./logs/alert/"
  27. if ps -a | grep "PrometheusAlert" | grep -v grep > /dev/null; then
  28. log_info "PrometheusAlert已在运行"
  29. elif [[ ! -f "./lib/PrometheusAlert" ]]; then
  30. log_info "no PrometheusAlert found, skip"
  31. else
  32. if [[ ! -d $log_path ]]; then
  33. mkdir -p "$log_path"
  34. fi
  35. log_file="alert_$(date "+%Y-%m-%d-%H:%M:%S").log"
  36. ./lib/PrometheusAlert &>> "${log_path}${log_file}" &
  37. sleep 1s
  38. if grep -E 'cannot|not defined' "${log_path}${log_file}" >> /dev/null; then
  39. log_err "PrometheusAlert启动遇到问题,请检查${log_file}"
  40. else
  41. log_info "PrometheusAlert启动成功!"
  42. fi
  43. fi