stopExporters.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. set +u
  3. set -e
  4. base_dir=$(
  5. cd "$(dirname "$0")"
  6. pwd
  7. )
  8. cd $base_dir
  9. if [[ $1 != "no_logo" ]]; then
  10. cat << 'LOGO'
  11. ###############################################################
  12. LOGO
  13. else
  14. shift 1
  15. fi
  16. # extra function
  17. ## func of log
  18. function log_warn() {
  19. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  20. local para=$1
  21. echo "[WARN] $date $1" | tee -a "./log/stop_log"
  22. }
  23. function log_info() {
  24. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  25. local para=$1
  26. echo "[INFO] $date $1" | tee -a "./log/stop_log"
  27. }
  28. function log_err() {
  29. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  30. local para=$1
  31. echo "[ERROR] $date $1" | tee -a "./log/stop_log"
  32. }
  33. function stop_process() {
  34. ID=$(ps -aux | grep "$1" | grep -v "$0" | grep -v "grep" | awk '{print $2}')
  35. if [[ "$ID" ]]; then
  36. log_info "$1 运行中,准备关闭"
  37. for id in $ID; do
  38. kill -15 "$id"
  39. echo "stop $1 process:(PID=${id})"
  40. done
  41. echo "---------------"
  42. fi
  43. }
  44. stop_process "node_exporter"
  45. stop_process "postgres_exporter"
  46. log_info "服务停止脚本运行完成"