Last active
March 28, 2016 11:53
-
-
Save philwinder/3611d13add2d930e045d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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