stop.sh 917 B

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