Archived
fix(deploy): remove sudo from docker commands; fix grep false-positive on inactive
nixos user is in the docker group so sudo is not needed (and breaks because sudo requires a TTY for password input). Also grep -q 'active' matched 'inactive' causing ha-docker-2 to be seen as already joined. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DASH15okNvWeY1rVJmyJoJ
This commit is contained in:
1 parent
9f1fed26c2
commit
2741451642
1 file changed
+5
-5
@@ -169,12 +169,12 @@ SWARM_USER="nixos"
|
|||||||
|
|
||||||
n1() {
|
n1() {
|
||||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
|
||||||
"${SWARM_USER}@${NODE1_LAN_IP}" sudo "$@" 2>/dev/null
|
"${SWARM_USER}@${NODE1_LAN_IP}" "$@" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
n2() {
|
n2() {
|
||||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
|
||||||
"${SWARM_USER}@${NODE2_LAN_IP}" sudo "$@" 2>/dev/null
|
"${SWARM_USER}@${NODE2_LAN_IP}" "$@" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
dc() {
|
dc() {
|
||||||
@@ -468,7 +468,7 @@ if ! $SKIP_INIT_SWARM; then
|
|||||||
logn "[dry-run] Would label both nodes"
|
logn "[dry-run] Would label both nodes"
|
||||||
else
|
else
|
||||||
# Check if node1 is already a swarm manager.
|
# Check if node1 is already a swarm manager.
|
||||||
if n1 "docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null | grep -q "active"; then
|
if n1 "docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null | grep -qx "active"; then
|
||||||
logn "${NODE1_HOST} is already in a swarm — skipping init."
|
logn "${NODE1_HOST} is already in a swarm — skipping init."
|
||||||
else
|
else
|
||||||
logn "Initialising swarm on ${NODE1_HOST} (advertise: ${NODE1_SWARM_IP})..."
|
logn "Initialising swarm on ${NODE1_HOST} (advertise: ${NODE1_SWARM_IP})..."
|
||||||
@@ -479,7 +479,7 @@ if ! $SKIP_INIT_SWARM; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if node2 is already joined.
|
# Check if node2 is already joined.
|
||||||
if n2 "docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null | grep -q "active"; then
|
if n2 "docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null | grep -qx "active"; then
|
||||||
logn "${NODE2_HOST} is already in the swarm — skipping join."
|
logn "${NODE2_HOST} is already in the swarm — skipping join."
|
||||||
else
|
else
|
||||||
logn "Fetching manager join token from ${NODE1_HOST}..."
|
logn "Fetching manager join token from ${NODE1_HOST}..."
|
||||||
@@ -559,7 +559,7 @@ if ! $SKIP_VERIFY; then
|
|||||||
for spec in "${NODE1_LAN_IP}:${NODE1_HOST}" "${NODE2_LAN_IP}:${NODE2_HOST}"; do
|
for spec in "${NODE1_LAN_IP}:${NODE1_HOST}" "${NODE2_LAN_IP}:${NODE2_HOST}"; do
|
||||||
IFS=: read -r ip hostname <<< "$spec"
|
IFS=: read -r ip hostname <<< "$spec"
|
||||||
STATE=$(ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no \
|
STATE=$(ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no \
|
||||||
"${SWARM_USER}@${ip}" "sudo docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null)
|
"${SWARM_USER}@${ip}" "docker info --format '{{.Swarm.LocalNodeState}}'" 2>/dev/null)
|
||||||
if [[ "$STATE" != "active" ]]; then
|
if [[ "$STATE" != "active" ]]; then
|
||||||
err "${hostname} swarm state is '${STATE}', expected 'active'"
|
err "${hostname} swarm state is '${STATE}', expected 'active'"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in new issue
Block a user