-
Notifications
You must be signed in to change notification settings - Fork 3
/
emergency-consul-down-and-up.sh
39 lines (27 loc) · 1.34 KB
/
emergency-consul-down-and-up.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
sudo sed -i -e "s/\r$//g" $(basename $0)
set -eu
sudo chmod a+x *.sh
echo "[NOTICE] Substituting CRLF with LF to prevent possible CRLF errors..."
bash prevent-crlf.sh
git config apply.whitespace nowarn
git config core.filemode false
sleep 3
source ./util.sh
source ./use-consul.sh
cache_non_dependent_global_vars
check_env_integrity
echo "[STRONG WARNING] This process removes all Containers in the Consul network, which means your running Apps will be stopped."
echo "[WARNING] This will re-create your network according to the orchestration_type on .env. (stack : swarm, compose : local). The current orchestration_type is '${orchestration_type}'"
network_name="consul"
docker stack rm ${project_name}-blue || echo "[DEBUG] D"
docker stack rm ${project_name}-green || echo "[DEBUG] E"
container_ids=($(docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' "$network_name")) || echo "[NOTICE] THe network name ${network_name} has NOT been found."
for container_id in "${container_ids[@]}"; do
echo "[NOTICE] Stopping & Removing containers for removing the Consul network : $container_id"
docker network disconnect -f "$network_name" "$container_id" || echo "[DEBUG] F"
docker stop "$container_id" || echo "[DEBUG] G"
docker container rm "$container_id" || echo "[DEBUG] H"
done
sleep 5
consul_down_and_up_with_network