stop.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. PrometheusAlert关闭服务脚本
  13. ###############################################################
  14. LOGO
  15. else
  16. shift 1
  17. fi
  18. # extra function
  19. ## func of log
  20. function log_warn() {
  21. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  22. local para=$1
  23. echo "[WARN] PrometheusAlert $date $1" | tee -a "../log/stop_log"
  24. }
  25. function log_info() {
  26. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  27. local para=$1
  28. echo "[INFO] PrometheusAlert $date $1" | tee -a "../log/stop_log"
  29. }
  30. function log_err() {
  31. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  32. local para=$1
  33. echo "[ERROR] PrometheusAlert $date $1" | tee -a "../log/stop_log"
  34. }
  35. function stop_process() {
  36. ID=$(ps -auxc | grep "$1" | grep -v "$0" | grep -v "grep" | awk '{print $2}')
  37. if [[ "$ID" ]]; then
  38. log_info "$1 运行中,准备关闭"
  39. for id in $ID; do
  40. kill -15 "$id"
  41. echo "stop $1 process:(PID=${id})"
  42. done
  43. echo "---------------"
  44. fi
  45. }
  46. stop_process "PrometheusAlert"
  47. log_info "PrometheusAlert服务停止脚本运行完成"