2014-10-17 12:40:31 +00:00
|
|
|
#!/bin/bash
|
2016-10-13 17:31:17 +08:00
|
|
|
if [[ $COMPUTE ]] && [[ $(pgrep qemu) ]]; then
|
2015-08-27 13:24:43 +00:00
|
|
|
echo "Some qemu processes were detected."
|
|
|
|
echo "Docker will not be able to stop the nova_libvirt container with those running."
|
|
|
|
echo "Please clean them up before rerunning this script."
|
|
|
|
exit 1
|
2015-08-31 04:14:17 +00:00
|
|
|
fi
|
2015-08-27 13:24:43 +00:00
|
|
|
|
2015-12-02 22:54:52 +00:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
containers_to_kill=($(docker ps | grep -E "$1" | awk '{print $1}'))
|
2016-02-16 22:17:22 +08:00
|
|
|
volumes_to_remove=($(docker volume ls | grep -E "$1" | awk '{print $1}'))
|
2015-12-02 22:54:52 +00:00
|
|
|
else
|
2016-06-14 15:12:02 +00:00
|
|
|
containers_to_kill=$(docker ps --filter "label=kolla_version" --format "{{.Names}}" -a)
|
2016-02-16 22:17:22 +08:00
|
|
|
|
2016-05-06 09:19:33 -03:00
|
|
|
volumes_to_remove=$(docker inspect -f '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' ${containers_to_kill} | \
|
|
|
|
egrep -v '(^\s*$)' | sort | uniq)
|
2015-12-02 22:54:52 +00:00
|
|
|
fi
|
2015-08-27 13:24:43 +00:00
|
|
|
|
|
|
|
echo "Stopping containers..."
|
2016-05-06 09:19:33 -03:00
|
|
|
(docker stop -t 2 ${containers_to_kill} 2>&1) > /dev/null
|
2015-08-27 13:24:43 +00:00
|
|
|
|
|
|
|
echo "Removing containers..."
|
2016-05-06 09:19:33 -03:00
|
|
|
(docker rm -v -f ${containers_to_kill} 2>&1) > /dev/null
|
2015-08-27 13:24:43 +00:00
|
|
|
|
2016-02-16 22:17:22 +08:00
|
|
|
echo "Removing volumes..."
|
2016-05-06 09:19:33 -03:00
|
|
|
(docker volume rm ${volumes_to_remove} 2>&1) > /dev/null
|
2016-02-16 22:17:22 +08:00
|
|
|
|
2015-08-27 13:24:43 +00:00
|
|
|
echo "All cleaned up!"
|