The little things give you away... A collection of various small helper stuff
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

47 строки
1.4 KiB

  1. #!/bin/bash
  2. set -e
  3. if [[ "$1" == '-h' || $# -ne 2 ]]
  4. then
  5. echo 'Usage: kill-wpull-connections (-p PID | -j JOBID | -h)'
  6. echo
  7. echo ' -h: Display this message and exit'
  8. echo ' -j JOBID: Kill connections of the wpull process for ArchiveBot job JOBID'
  9. echo ' -p PID: Kill connections of wpull process PID'
  10. [[ "$1" == '-h' && $# -eq 1 ]] && exit 0 || exit 1
  11. fi
  12. if [[ "$1" == '-p' ]]
  13. then
  14. wpullPid=$2
  15. if [[ "${wpullPid}" == *[^0-9]* ]]
  16. then
  17. echo "Error: '${wpullPid}' is not a valid PID"
  18. exit 1
  19. fi
  20. elif [[ "$1" == '-j' ]]
  21. then
  22. pids=($(pgrep --full "wpull.*/$2/"))
  23. if [[ ${#pids[@]} -ne 1 ]]
  24. then
  25. echo "Error: not exactly one process found for '$2'"
  26. exit 1
  27. fi
  28. wpullPid=${pids[0]}
  29. fi
  30. if ! kill -0 ${wpullPid} >/dev/null 2>&1
  31. then
  32. echo "Error: no process with PID ${wpullPid}"
  33. exit 1
  34. fi
  35. gdb -batch -batch-silent \
  36. -ex "attach ${wpullPid}" \
  37. -ex 'shell echo "FDs before forced shutdown:"; lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1' \
  38. -ex 'python import subprocess' \
  39. -ex 'python for fd in subprocess.check_output("lsof -an -p '${wpullPid}' -i TCP -F pfn | awk '\''NR%2==0{fd=substr($0,2)}NR%2==1&&NR>1&&!/127\.0\.0\.1/{print fd}'\''", shell = True).decode("ascii").strip().split("\n"): gdb.execute("p shutdown(" + fd + ", 2)")' \
  40. -ex 'shell echo "FDs after forced shutdown:"; lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1' \
  41. -ex detach \
  42. -ex quit