You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
921 B

  1. #!/bin/bash
  2. exname=$(basename "$0")
  3. usage="$exname [-h|--help] CONTAINER SIGNAL"
  4. container=
  5. signal=
  6. while [ "$1" ]; do
  7. case "$1" in
  8. "--help"|"-h")
  9. echo "$usage" >&2
  10. exit 0
  11. ;;
  12. *)
  13. [ -z "$container" ] && { container=$1 ; shift ; continue ; }
  14. [ -z "$signal" ] && { signal=$1 ; shift ; continue ; }
  15. echo "Unexpected argument '$1'." >&2
  16. exit 1
  17. ;;
  18. esac
  19. shift
  20. done
  21. if [ -z "$container" ]; then
  22. echo "You must provide a container name/id as first argument." >&2
  23. echo "$usage" >&2
  24. exit 1
  25. fi
  26. if [ -z "$signal" ]; then
  27. echo "You must provide a signal to send to $container aargument." >&2
  28. echo "$usage" >&2
  29. exit 1
  30. fi
  31. container_id="$(docker inspect --format="{{ .Id }}" "$container")"
  32. echo -e "POST /containers/$container_id/kill?signal=$signal HTTP/1.0\r\n" | nc -U /var/run/docker.sock