forked from lei.chen/myxce
- ha.c: add raft_cb_trace callback wired to s_real_cbs.on_trace; emits RAFT[pN] term=T event=E at DEBUG3 level, visible with -vvv flag. - ha.c: repl_ack_decode_and_dispatch now silently drops OPCode_nop and OPCode_reply instead of WARNING — heartbeat NOP replies from standbys arrive on promoted endpoints and are expected. - deploy-ha.sh: fix --vcpu -> --vcpus; add \$VERBOSE passthrough so start.sh respects VERBOSE=-vvv from the environment.
78 lines
1.8 KiB
Bash
Executable file
78 lines
1.8 KiB
Bash
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
BINARY=$1
|
|
DATADIR=$2
|
|
TOP=$3
|
|
PEERS=$4
|
|
|
|
if [ -z "$BINARY" ] || [ -z "$DATADIR" ] || [ -z "$TOP" ] || [ -z "$PEERS" ]; then
|
|
echo "Usage: $0 <binary> <data-dir> <top-dir> <peers>"
|
|
echo " peers: comma-separated host:port list (e.g. host1:port1,host2:port2)"
|
|
exit 1
|
|
fi
|
|
|
|
BINARY=$(realpath "$BINARY")
|
|
|
|
IFS=',' read -ra PEER_ARRAY <<< "$PEERS"
|
|
N=${#PEER_ARRAY[@]}
|
|
|
|
# Create directory structure
|
|
mkdir -p "$TOP/certs"
|
|
mkdir -p "$TOP/logs"
|
|
mkdir -p "$TOP/scripts"
|
|
for i in $(seq 1 $N); do
|
|
mkdir -p "$TOP/ctrl-$i/conf"
|
|
mkdir -p "$TOP/ctrl-$i/data"
|
|
done
|
|
|
|
# Copy certificates
|
|
cp "$DATADIR/xce.crt" "$TOP/certs/"
|
|
cp "$DATADIR/xce.key" "$TOP/certs/"
|
|
|
|
# Tag and copy cluster.bin
|
|
TAG=$(sha256sum "$DATADIR/cluster.bin" | cut -c1-12)
|
|
cp "$DATADIR/cluster.bin" "$TOP/ctrl-1/conf/cluster.bin.$TAG"
|
|
echo "cluster.bin.$TAG" > "$TOP/ctrl-1/conf/current"
|
|
|
|
# Build peers string: ctrl-1=host1:port1,ctrl-2=host2:port2,...
|
|
PEERS_STR=""
|
|
for i in "${!PEER_ARRAY[@]}"; do
|
|
n=$((i+1))
|
|
[ -n "$PEERS_STR" ] && PEERS_STR+=","
|
|
PEERS_STR+="ctrl-$n=${PEER_ARRAY[$i]}"
|
|
done
|
|
|
|
# Generate start script
|
|
cat > "$TOP/scripts/start.sh" << EOF
|
|
#!/bin/bash
|
|
set -e
|
|
NAME=\$1
|
|
if [ -z "\$NAME" ]; then
|
|
echo "Usage: \$0 <ctrl-name>"
|
|
exit 1
|
|
fi
|
|
CTRL_DIR=$TOP/\$NAME
|
|
if [ ! -d "\$CTRL_DIR/conf" ] || [ ! -d "\$CTRL_DIR/data" ]; then
|
|
echo "Error: \$CTRL_DIR/conf or \$CTRL_DIR/data does not exist"
|
|
exit 1
|
|
fi
|
|
$BINARY --myname \$NAME --peers "$PEERS_STR" --workdir $TOP --logfile $TOP/logs/\$NAME.log --vcpus 4 \$VERBOSE
|
|
EOF
|
|
chmod +x "$TOP/scripts/start.sh"
|
|
|
|
# Generate cleanup script
|
|
cat > "$TOP/scripts/cleanup.sh" << EOF
|
|
#!/bin/bash
|
|
set -e
|
|
rm -f $TOP/logs/*.log
|
|
for i in \$(seq 1 $N); do
|
|
rm -rf $TOP/ctrl-\$i/data/*
|
|
done
|
|
for i in \$(seq 2 $N); do
|
|
rm -rf $TOP/ctrl-\$i/conf/*
|
|
done
|
|
EOF
|
|
chmod +x "$TOP/scripts/cleanup.sh"
|
|
|
|
echo "Deployed $N-node cluster to $TOP (tag: $TAG)"
|