Created
November 22, 2020 18:42
-
-
Save tom-doerr/ab3cd5f39d29ba04072c9fc90113c84d to your computer and use it in GitHub Desktop.
Starts and kills the docker container when memory is low
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 | |
CONTAINER_NAME="commonroad_container" | |
MIN_FREE_GB=2 | |
SLEEP_TIME_MEMORY_CHECK=0.1 | |
trap 'kill $pid_to_kill_exit; exit' INT | |
kill_low_memory() { | |
while true | |
do | |
if (( $(free -g | awk '/Mem/ {print $7}') < $MIN_FREE_GB )) | |
then | |
docker kill $CONTAINER_NAME | |
fi | |
sleep $SLEEP_TIME_MEMORY_CHECK | |
done | |
} | |
kill_low_memory & | |
pid_to_kill_exit=$! | |
docker run -it --rm -p 9000:8888 --name $CONTAINER_NAME --mount src="$(pwd)",target=/commonroad/commonroad-search,type=bind gitlab.lrz.de:5005/tum-cps/commonroad-search:2020_AI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment