The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

58 lignes
1.6 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 ! command -v lsof >/dev/null 2>&1
  31. then
  32. echo "Error: could not find lsof"
  33. exit 1
  34. fi
  35. if ! command -v gdb >/dev/null 2>&1
  36. then
  37. echo "Error: could not find gdb"
  38. exit 1
  39. fi
  40. if ! kill -0 ${wpullPid} >/dev/null 2>&1
  41. then
  42. echo "Error: no process with PID ${wpullPid}"
  43. exit 1
  44. fi
  45. gdb -batch -batch-silent \
  46. -ex "attach ${wpullPid}" \
  47. -ex 'python import subprocess' \
  48. -ex 'python def call(s): return subprocess.call(s, shell = True) == 0' \
  49. -ex 'python call("echo '\''FDs before forced shutdown:'\''") and call("lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1") and ([gdb.execute("p shutdown(" + fd + ", 2)") 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")] or True) and call("echo '\''FDs after forced shutdown:'\''") and call("lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1")' \
  50. -ex detach \
  51. -ex quit