run.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. prometheuslog_path="./log/prometheus/"
  27. # prometheus section
  28. if ps -auxc | grep "prometheus" | grep -v grep > /dev/null; then
  29. log_info "prometheus 已在运行"
  30. elif [[ ! -f "./lib/prometheus" ]]; then
  31. log_info "no prometheus found, skip"
  32. else
  33. if [[ ! -d $prometheuslog_path ]]; then
  34. mkdir "$prometheuslog_path"
  35. fi
  36. log_prometheus_file="prometheus_$(date "+%Y-%m-%d-%H:%M:%S").log"
  37. ./lib/prometheus --config.file=prometheus.yml --web.listen-address=:9990 --web.enable-lifecycle &>> "${prometheuslog_path}${log_prometheus_file}" &
  38. sleep 1
  39. if grep -E 'cannot|not defined|License does not exist' "${prometheuslog_path}${log_prometheus_file}" >> /dev/null; then
  40. log_err "prometheus 启动遇到问题,请检查${log_exporter_file}"
  41. else
  42. log_info "prometheus 启动成功!"
  43. fi
  44. fi
  45. alertmanagerlog_path="./log/alertmanager/"
  46. # alertmanager section
  47. if ps -auxc | grep "alertmanager" | grep -v grep > /dev/null; then
  48. log_info "alertmanager 已在运行"
  49. elif [[ ! -f "./lib/alertmanager" ]]; then
  50. log_info "no alertmanager found, skip"
  51. else
  52. if [[ ! -d $alertmanagerlog_path ]]; then
  53. mkdir "$alertmanagerlog_path"
  54. fi
  55. log_alertmanager_file="alertmanager_$(date "+%Y-%m-%d-%H:%M:%S").log"
  56. ./lib/alertmanager --config.file=alertmanager.yml --web.listen-address=:9993 &>> "${alertmanagerlog_path}${log_alertmanager_file}" &
  57. sleep 1
  58. if grep -E 'cannot|not defined|License does not exist' "${alertmanagerlog_path}${log_alertmanager_file}" >> /dev/null; then
  59. log_err "alertmanager 启动遇到问题,请检查${log_alertmanager_file}"
  60. else
  61. log_info "alertmanager 启动成功!"
  62. fi
  63. fi
  64. #dingtalklog_path="./log/dingtalk/"
  65. ## dingtalk section
  66. #if ps -auxc | grep "dingtalk" | grep -v grep > /dev/null; then
  67. # log_info "dingtalk 已在运行"
  68. #elif [[ ! -f "./lib/dingtalk" ]]; then
  69. # log_info "no dingtalk found, skip"
  70. #else
  71. #
  72. # if [[ ! -d $dingtalklog_path ]]; then
  73. # mkdir "$dingtalklog_path"
  74. # fi
  75. #
  76. # log_dingtalk_file="dingtalk_$(date "+%Y-%m-%d-%H:%M:%S").log"
  77. # ./lib/dingtalk --config.file=dingtalk.yml --web.listen-address=:9994 --web.enable-ui &>> "${dingtalklog_path}${log_dingtalk_file}" &
  78. # sleep 1
  79. # if grep -E 'cannot|not defined|License does not exist' "${dingtalklog_path}${log_dingtalk_file}" >> /dev/null; then
  80. # log_err "dingtalk 启动遇到问题,请检查${log_dingtalk_file}"
  81. # else
  82. # log_info "dingtalk 启动成功!"
  83. # fi
  84. #fi