2014-10-17 12:40:31 +00:00
|
|
|
#!/bin/bash
|
2017-01-16 15:46:38 +00:00
|
|
|
|
2019-04-09 11:59:02 +00:00
|
|
|
containers_running=$(sudo docker ps --filter "label=kolla_version" --format "{{.Names}}")
|
2017-01-16 15:46:38 +00:00
|
|
|
|
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
|
2019-04-09 11:59:02 +00:00
|
|
|
containers_to_kill=$(sudo docker ps --filter "label=kolla_version" --format "{{.Names}}" -a | grep -E "$1" | awk '{print $1}')
|
|
|
|
volumes_to_remove=$(sudo docker inspect -f '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' ${containers_to_kill} | \
|
2017-03-20 12:19:17 +08:00
|
|
|
egrep -v '(^\s*$)' | sort | uniq)
|
2015-12-02 22:54:52 +00:00
|
|
|
else
|
2019-04-09 11:59:02 +00:00
|
|
|
containers_to_kill=$(sudo docker ps --filter "label=kolla_version" --format "{{.Names}}" -a)
|
2016-02-16 22:17:22 +08:00
|
|
|
|
2019-04-09 11:59:02 +00:00
|
|
|
volumes_to_remove=$(sudo docker inspect -f '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' ${containers_to_kill} | \
|
2016-05-06 09:19:33 -03:00
|
|
|
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..."
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker exec -u root neutron_openvswitch_agent neutron-ovs-cleanup \
|
2016-11-13 16:15:08 +00:00
|
|
|
--config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
|
|
|
|
--ovs_all_ports) > /dev/null
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker exec -it openvswitch_vswitchd bash -c 'for br in `ovs-vsctl list-br`;do ovs-vsctl --if-exists del-br $br;done') > /dev/null
|
2016-11-13 16:15:08 +00:00
|
|
|
fi
|
|
|
|
|
2015-08-27 13:24:43 +00:00
|
|
|
echo "Stopping containers..."
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker stop -t 2 ${containers_to_kill} 2>&1) > /dev/null
|
2015-08-27 13:24:43 +00:00
|
|
|
|
|
|
|
echo "Removing containers..."
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker rm -v -f ${containers_to_kill} 2>&1) > /dev/null
|
2015-08-27 13:24:43 +00:00
|
|
|
|
2018-05-07 16:23:02 -03:00
|
|
|
echo "Disconnecting containers from docker host network"
|
|
|
|
for container in ${containers_to_kill}; do
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker network disconnect -f host $container 2>&1) > /dev/null
|
2018-05-07 16:23:02 -03:00
|
|
|
done
|
|
|
|
|
2016-02-16 22:17:22 +08:00
|
|
|
echo "Removing volumes..."
|
2019-04-09 11:59:02 +00:00
|
|
|
(sudo docker volume rm ${volumes_to_remove} 2>&1) > /dev/null
|
2016-02-16 22:17:22 +08:00
|
|
|
|
2019-01-23 14:08:25 +08:00
|
|
|
echo "Removing link of kolla_log volume..."
|
2020-08-20 17:55:49 +08:00
|
|
|
(sudo rm -f /var/log/kolla 2>&1) > /dev/null
|
2019-01-23 14:08:25 +08:00
|
|
|
|
2015-08-27 13:24:43 +00:00
|
|
|
echo "All cleaned up!"
|