Skip to content

Instantly share code, notes, and snippets.

@philwinder
Last active March 28, 2016 11:53
Show Gist options
  • Save philwinder/3611d13add2d930e045d to your computer and use it in GitHub Desktop.
Save philwinder/3611d13add2d930e045d to your computer and use it in GitHub Desktop.
#!/bin/bash
function mesosContainerList() {
count=0
for item in $(docker ps -q)
do
mesosName=$(docker exec -i $item sh -c 'echo $MESOS_CONTAINER_NAME')
echo $mesosName
if [ -n "${mesosName//[$'\r\n\t ']}" ];
then
mesosContainers[$count]=$item
echo "$count: $item"
count=$((count+1))
fi
done
}
while true ;
do
sleepTime=$[ ( $RANDOM % 25 ) + 5 ]
echo "Sleeping for $sleepTime s"
sleep ${sleepTime}s ;
mesosContainerList
echo "Container list: ${mesosContainers[*]}"
len=${#mesosContainers[@]}
randomIndex=$(awk 'BEGIN{srand();print int(rand()*'$len') }')
randomContainer=${mesosContainers[$randomIndex]}
echo "Killing container with id: $randomContainer"
docker kill -s SIGKILL $randomContainer
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment