status.sh 666 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. set -e
  3. cat << 'LOGO'
  4. ----------------------------------
  5. LOGO
  6. base_dir=$(
  7. cd "$(dirname "$0")"
  8. pwd
  9. )
  10. cd $base_dir
  11. BINARY_NAME="nsq-server"
  12. server_pid=$(pgrep -x $BINARY_NAME || true)
  13. if [[ $server_pid == "" ]]; then
  14. echo "nsq-server 未在运行"
  15. else
  16. for pid in $server_pid; do
  17. running_time=$(ps -o etime= -p "$pid")
  18. ports=$(ss -tnlp | grep $BINARY_NAME | awk '{print $4}')
  19. echo "nsq-server 当前PID: $pid"
  20. echo "当前运行时间: $running_time" | tr -s " "
  21. echo "当前运行端口:"
  22. for port in $ports; do
  23. echo "$port"
  24. break
  25. done
  26. done
  27. fi