Skip to content

Commit e4644c4

Browse files
committed
Improve cleanup and run scripts for local dev
1 parent 4edbbf8 commit e4644c4

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

hack/cleanup.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ cleanup_env() {
6161
for env in "${ENVS_TO_CLEAN[@]}"; do
6262
case $env in
6363
rs)
64-
cleanup_env "rs" "$SCRIPT_DIR/rs/compose.yml"
65-
docker volume ls -q | grep -E '^rs[0-9]+' | xargs -r docker volume rm 2>/dev/null || true
64+
cleanup_env "rs" "$SCRIPT_DIR/rs/compose.yml" "r1"
65+
docker volume ls -q | grep -E '^r1_rs[0-9]+' | xargs -r docker volume rm 2>/dev/null || true
66+
docker network ls -q --filter "name=r1_" | xargs -r docker network rm 2>/dev/null || true
6667
;;
6768
sh)
6869
cleanup_env "sh" "$SCRIPT_DIR/sh/compose.yml" "s1"
6970
docker volume ls -q | grep -E '^(src-|tgt-|s1_)' | xargs -r docker volume rm 2>/dev/null || true
71+
docker network ls -q --filter "name=s1_" | xargs -r docker network rm 2>/dev/null || true
7072
;;
7173
sh-ha)
7274
cleanup_env "sh-ha" "$SCRIPT_DIR/sh-ha/compose.yml" "s1"
7375
docker volume ls -q | grep -E '^s1_' | xargs -r docker volume rm 2>/dev/null || true
76+
docker network ls -q --filter "name=s1_" | xargs -r docker network rm 2>/dev/null || true
7477
;;
7578
esac
7679
done

hack/rs/run.sh

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
#!/usr/bin/env bash
2+
# Start MongoDB replica sets for source and target
3+
#
4+
# Usage:
5+
# ./run.sh # Default: start both rs0 and rs1
6+
# RS_COUNT=1 ./run.sh # Start only rs0
7+
# RS_COUNT=2 ./run.sh # Start both rs0 and rs1
8+
#
9+
# Limits: Max 2 replica sets (rs0 and rs1)
10+
# Each replica set has 3 members (rs{N}0, rs{N}1, rs{N}2)
11+
# Ports: rs0 uses 30000-30002, rs1 uses 30100-30102
12+
13+
export COMPOSE_PROJECT_NAME=r1
214

315
BASE=$(dirname "$(dirname "$0")")
16+
echo "BASE=$BASE"
417

518
# shellcheck source=/dev/null
619
source "$BASE/util"
@@ -9,16 +22,55 @@ RDIR="$BASE/rs"
922

1023
export compose="$RDIR/compose.yml"
1124

12-
dcf up -d rs00 rs01 rs02 rs10 rs11 rs12
25+
# Port mappings for each replica set (must match compose.yml)
26+
# rs0: 30000, 30001, 30002
27+
# rs1: 30100, 30101, 30102
28+
RS_PORTS=(
29+
"30000 30001 30002"
30+
"30100 30101 30102"
31+
)
32+
33+
# Dynamically defined by the length of sets of ports
34+
MAX_RS_COUNT=${#RS_PORTS[@]}
35+
36+
# Configuration: Number of replica sets to start
37+
# Can be overridden with environment variable: RS_COUNT=1 ./run.sh
38+
RS_COUNT="${RS_COUNT:-$MAX_RS_COUNT}"
39+
40+
if [ "$RS_COUNT" -gt "$MAX_RS_COUNT" ]; then
41+
echo "ERROR: RS_COUNT=$RS_COUNT exceeds maximum $MAX_RS_COUNT"
42+
echo "Available init scripts: $RDIR/mongo/scripts/rs{0..$((MAX_RS_COUNT-1))}.js"
43+
exit 1
44+
fi
45+
46+
if [ "$RS_COUNT" -lt 1 ]; then
47+
echo "ERROR: RS_COUNT=$RS_COUNT must be at least 1"
48+
exit 1
49+
fi
50+
51+
echo "Starting $RS_COUNT replica set(s) (max: $MAX_RS_COUNT)"
52+
53+
# Build list of services to start and initialize each replica set
54+
SERVICES=""
55+
for rs_idx in $(seq 0 $((RS_COUNT - 1))); do
56+
echo "Starting replica set rs${rs_idx}"
57+
SERVICES="$SERVICES rs${rs_idx}0 rs${rs_idx}1 rs${rs_idx}2"
58+
done
1359

14-
mwait "rs00:30000"
15-
mwait "rs01:30001"
16-
mwait "rs02:30002"
60+
# Start the selected services
61+
dcf up -d $SERVICES
1762

18-
rsinit "scripts/rs0" "rs00:30000"
63+
# Initialize each replica set
64+
for rs_idx in $(seq 0 $((RS_COUNT - 1))); do
65+
# Get ports for this replica set
66+
read -r -a PORTS <<< "${RS_PORTS[$rs_idx]}"
1967

20-
mwait "rs10:30100"
21-
mwait "rs11:30101"
22-
mwait "rs12:30102"
68+
# Wait for all members
69+
for member_idx in 0 1 2; do
70+
PORT=${PORTS[$member_idx]}
71+
mwait "rs${rs_idx}${member_idx}:${PORT}"
72+
done
2373

24-
rsinit "scripts/rs1" "rs10:30100"
74+
# Initialize replica set
75+
rsinit "scripts/rs${rs_idx}" "rs${rs_idx}0:${PORTS[0]}"
76+
done

0 commit comments

Comments
 (0)