Skip to content

Instantly share code, notes, and snippets.

@urjitbhatia
Created June 11, 2020 19:26
Show Gist options
  • Save urjitbhatia/29d77645ebff7efa8bf9d24fd77ca528 to your computer and use it in GitHub Desktop.
Save urjitbhatia/29d77645ebff7efa8bf9d24fd77ca528 to your computer and use it in GitHub Desktop.
Send signal to docker container via docker socket from commandline script
# This script will send a signal to a container
# Sleep for a random time b/w 1 to 3 seconds to avoid restarting at the exact same time
# This bc format of finding random doesn't print scientific notation which sometimes sleep doesn't like a lot
/bin/sleep "$(echo "scale=3; 0.5 + 2.5 * $RANDOM / 32767" | bc)s"
## Running in silent curl mode (-s and > /dev/null) - remember while debugging
if curl --silent --show-error --output /dev/null --unix-socket /var/run/docker.sock -X POST "http/containers/${CONTAINER_ID}/kill?signal=SIGUSR2" ; then
echo "Successfully sent signal to $CONTAINER_ID"
else
echo "Failed to send signal to $CONTAINER_ID. Triggering alarms."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment