Last active
February 23, 2026 16:59
-
-
Save thiagozs/1b5592173c20e67a1a5e3766edcc2cfe to your computer and use it in GitHub Desktop.
Init cluster rabbitmq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| echo "#########################################" | |
| echo "### INIT SCRIPT VERSION: 2026-02-23-v6 ###" | |
| echo "#########################################" | |
| get_container_id() { | |
| docker ps --filter "name=$1" --format "{{.ID}}" | head -n 1 | |
| } | |
| wait_for_port() { | |
| NAME="$1" | |
| echo "⏳ Esperando $NAME porta 5672 abrir..." | |
| while ! nc -z "$NAME" 5672 > /dev/null 2>&1; do | |
| sleep 3 | |
| done | |
| echo "✅ $NAME porta pronta." | |
| } | |
| wait_for_port rabbit1 | |
| wait_for_port rabbit2 | |
| wait_for_port rabbit3 | |
| echo "🔧 Formando cluster..." | |
| R2=$(get_container_id rabbit2) | |
| R3=$(get_container_id rabbit3) | |
| R1=$(get_container_id rabbit1) | |
| echo "rabbit1 id: $R1" | |
| echo "rabbit2 id: $R2" | |
| echo "rabbit3 id: $R3" | |
| docker exec "$R2" rabbitmqctl stop_app | |
| docker exec "$R2" rabbitmqctl reset | |
| docker exec "$R2" rabbitmqctl join_cluster rabbit@rabbit1 | |
| docker exec "$R2" rabbitmqctl start_app | |
| docker exec "$R3" rabbitmqctl stop_app | |
| docker exec "$R3" rabbitmqctl reset | |
| docker exec "$R3" rabbitmqctl join_cluster rabbit@rabbit1 | |
| docker exec "$R3" rabbitmqctl start_app | |
| echo "✅ Cluster formado!" | |
| docker exec "$R1" rabbitmqctl cluster_status | |
| echo "🎉 Processo concluído!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment