Skip to content

Commit 0934599

Browse files
committed
Removing volumes
1 parent 4706404 commit 0934599

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

services/rabbit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
docker-compose.yml
2+
docker-compose*.yaml
23
!erlang.cookie.secret.template
34
rabbitmq.conf
45
haproxy.cfg

services/rabbit/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
22

33
include ${REPO_BASE_DIR}/scripts/common-services.Makefile
44
# common-services.Makefile should be included first as common.Makefile
5-
#relies on STACK_NAME var which is defined in common-services.Makefile
5+
# relies on STACK_NAME var which is defined in common-services.Makefile
66
include ${REPO_BASE_DIR}/scripts/common.Makefile
77

88
.PHONY: up
@@ -36,3 +36,20 @@ haproxy.cfg: haproxy.cfg.j2 .env venv
3636

3737
docker-compose.yml: docker-compose.yml.j2 .env rabbitmq.conf erlang.cookie.secret haproxy.cfg venv $(VENV_BIN)/j2
3838
@$(call jinja, $<, .env, $@)
39+
40+
#
41+
# Deleting volumes (data)
42+
#
43+
44+
TEMP_COMPOSE_OPERATOR := .stack.${STACK_NAME}.operator.yaml
45+
STACK_NAME_OPERATOR := ${STACK_NAME}-operator
46+
47+
docker-compose.operator.yaml: docker-compose.operator.yaml.j2 .env
48+
@$(call jinja, $<, .env, $@)
49+
50+
${TEMP_COMPOSE_OPERATOR}: docker-compose.operator.yaml .env
51+
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
52+
53+
destroy-cluster-with-data: ${TEMP_COMPOSE_OPERATOR} .env down
54+
@docker stack rm ${STACK_NAME_OPERATOR}
55+
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE_OPERATOR} ${STACK_NAME_OPERATOR}

services/rabbit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Make sure all nodes have joined the cluster before using it. Otherwise, number o
44

55
## Updating rabbitmq.conf / advanced.config (zero-downtime)
66

7-
We do not support this automated. But manually this can be achieved in case needed. `rabbitmq.conf` and `advanced.config` changes take effect after a node restart. This can be performed with zero-downtime when RabbitMQ is clustered (have multiple nodes). This can be achieved by stopping and starting rabbitmq nodes one by one
7+
We do not support this automated (except starting from scratch with empty volumes). But manually this can be achieved in case needed. `rabbitmq.conf` and `advanced.config` changes take effect after a node restart. This can be performed with zero-downtime when RabbitMQ is clustered (have multiple nodes). This can be achieved by stopping and starting rabbitmq nodes one by one
88
* `docker exec -it <container-id> bash`
99
* (inside container) `rabbitmqctl stop_app` and wait some time until node is stopped (can be seen in management ui)
1010
* (inside container) `rabbitmqctl start_app`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% set NODE_IXS = range(1, (RABBIT_CLUSTER_NODE_COUNT | int) + 1) -%}
2+
3+
services:
4+
5+
{% for ix in NODE_IXS %}
6+
clean_rabbit0{{ ix }}_volume:
7+
image: docker:25.0.3-cli
8+
volumes:
9+
- /var/run/docker.sock:/var/run/docker.sock
10+
init: true
11+
deploy:
12+
placement:
13+
constraints:
14+
- node.labels.rabbit0{{ ix }} == true
15+
restart_policy:
16+
condition: none
17+
resources:
18+
limits:
19+
cpus: "1.0"
20+
memory: "1G"
21+
reservations:
22+
cpus: "0.1"
23+
memory: "128M"
24+
configs:
25+
- source: delete_docker_volume_on_node_script
26+
target: /app/delete_docker_volume_on_node.sh
27+
mode: 0755
28+
environment:
29+
VOLUME: ${STACK_NAME}0{{ ix }}_data
30+
TIMEOUT: 120
31+
INTERVAL: 5
32+
entrypoint: ["/app/delete_docker_volume_on_node.sh"]
33+
{% endfor %}
34+
35+
configs:
36+
delete_docker_volume_on_node_script:
37+
file: ./operator/delete_docker_volume_on_node.sh
38+
name: ${STACK_NAME}_delete_docker_volume_on_node_script_{{ "./operator/delete_docker_volume_on_node.sh" | sha256file | substring(0,10) }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
VOLUME="${VOLUME:-}"
5+
TIMEOUT="${TIMEOUT:-60}"
6+
INTERVAL="${INTERVAL:-5}"
7+
8+
if [ -z "$VOLUME" ]; then
9+
echo "ERROR: VOLUME not set. Usage: VOLUME=name [TIMEOUT=60] [INTERVAL=5] $0"
10+
exit 1
11+
fi
12+
13+
echo "Deleting volume '$VOLUME'"
14+
echo "Timeout: ${TIMEOUT}s"
15+
echo "Interval: ${INTERVAL}s"
16+
17+
if ! docker volume inspect "$VOLUME" >/dev/null 2>&1; then
18+
echo "Volume '$VOLUME' does not exist. Nothing to do."
19+
exit 0
20+
fi
21+
22+
elapsed=0
23+
while [ "$elapsed" -lt "$TIMEOUT" ]; do
24+
if docker volume rm "$VOLUME" >/dev/null 2>&1; then
25+
echo "Volume '$VOLUME' removed successfully."
26+
exit 0
27+
fi
28+
remaining=$(( TIMEOUT - elapsed ))
29+
echo "Volume '$VOLUME' still in use. Retrying in ${INTERVAL}s. Time left: ${remaining}s."
30+
sleep "$INTERVAL"
31+
elapsed=$(( elapsed + INTERVAL ))
32+
done
33+
34+
echo "Timeout reached. Exiting."
35+
exit 1

0 commit comments

Comments
 (0)