stop.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. 关闭服务脚本
  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] $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] $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] $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. if [[ -z $1 ]]; then
  47. stop_process "traefik"
  48. log_info "服务停止脚本运行完成"
  49. fi