2014-10-17 12:40:31 +00:00
|
|
|
#!/bin/bash
|
2017-01-16 15:46:38 +00:00
|
|
|
|
|
|
|
containers_running=$(docker ps --filter "label=kolla_version" --format "{{.Names}}")
|
|
|
|
|
2017-02-02 09:49:12 +00:00
|
|
|
QEMU_PIDS=$(pgrep -l qemu | awk '!/qemu-ga/ && !/qemu-img/ {print $1}')
|
2017-01-16 15:46:38 +00:00
|
|
|
if [[ "${containers_running}" =~ "nova_libvirt" ]] && [[ $QEMU_PIDS ]] && [[ $(ps --no-headers wwwup $QEMU_PIDS | grep --invert-match '\-xen\-domid 0') ]]; 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
|
2016-11-13 16:15:08 +00:00
|
|
|
containers_to_kill=($(docker ps --filter "label=kolla_version" --format "{{.Names}}" -a | grep -E "$1" | awk '{print $1}'))
|
|
|
|
volumes_to_remove=($(docker inspect -f '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' $1 | \
|
|
|
|
egrep -v '(^\s*$)' | sort | uniq))
|
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
|
|
|
|
2016-11-13 16:15:08 +00:00
|
|
|
if [[ "${containers_to_kill}" =~ "openvswitch_vswitchd" ]] && [[ "${containers_running}" =~ "neutron_openvswitch_agent" ]]; then
|
|
|
|
echo "Removing ovs bridge..."
|
|
|
|
(docker exec -u root neutron_openvswitch_agent neutron-ovs-cleanup \
|
|
|
|
--config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
|
|
|
|
--ovs_all_ports) > /dev/null
|
|
|
|
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!"
|