true bidirectional with split truth modle set up. all scripts are fully bidirectional
This commit is contained in:
@@ -519,15 +519,15 @@ RUNNING_CONTAINERS=()
|
||||
stop_containers() {
|
||||
if [[ ${#CRITICAL_CONTAINER_NAMES[@]} -eq 0 ]] || \
|
||||
[[ "${CRITICAL_CONTAINER_NAMES[*]}" == "" ]]; then
|
||||
log "No containers configured for this profile, skipping stop."
|
||||
log "No remote containers configured for this profile, skipping stop."
|
||||
return
|
||||
fi
|
||||
info "Stopping containers..."
|
||||
info "Stopping remote containers..."
|
||||
RUNNING_CONTAINERS=()
|
||||
for c in "${CRITICAL_CONTAINER_NAMES[@]}"; do
|
||||
[[ -z "$c" ]] && continue
|
||||
STATUS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \
|
||||
"docker inspect -f '{{.State.Running}}' $c 2>/dev/null" 2>/dev/null || echo "false")
|
||||
"docker inspect -f '{{.State.Running}}' $c 2>/dev/null" 2>/dev/null || echo "unknown")
|
||||
if [[ "$STATUS" == "true" ]]; then
|
||||
echo "$ICON_STOP Stopping $c..."
|
||||
RUNNING_CONTAINERS+=("$c")
|
||||
@@ -536,8 +536,44 @@ stop_containers() {
|
||||
else
|
||||
error "Failed to stop $c"
|
||||
fi
|
||||
else
|
||||
elif [[ "$STATUS" == "false" ]]; then
|
||||
echo "$ICON_NOT_RUNNING $c is not running, skipping"
|
||||
else
|
||||
log "$c not found on remote — skipping"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# CONTAINER MANAGEMENT — STOP LOCAL
|
||||
# Stops containers on the LOCAL server before rsync pushes data out.
|
||||
# Uses PROFILE_LOCAL_CRITICAL_CONTAINER_NAMES — same naming scheme as remote.
|
||||
# If container not found on this server → skipped gracefully, not errored.
|
||||
# Only containers that were running get tracked for restart.
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
stop_local_containers() {
|
||||
if [[ ${#LOCAL_CRITICAL_CONTAINER_NAMES[@]} -eq 0 ]] || \
|
||||
[[ "${LOCAL_CRITICAL_CONTAINER_NAMES[*]}" == "" ]]; then
|
||||
log "No local containers configured for this profile, skipping local stop."
|
||||
return
|
||||
fi
|
||||
info "Stopping local containers..."
|
||||
LOCAL_RUNNING_CONTAINERS=()
|
||||
for c in "${LOCAL_CRITICAL_CONTAINER_NAMES[@]}"; do
|
||||
[[ -z "$c" ]] && continue
|
||||
STATUS=$(docker inspect -f '{{.State.Running}}' "$c" 2>/dev/null || echo "unknown")
|
||||
if [[ "$STATUS" == "true" ]]; then
|
||||
echo "$ICON_STOP Stopping local $c..."
|
||||
LOCAL_RUNNING_CONTAINERS+=("$c")
|
||||
if docker stop "$c" >/dev/null; then
|
||||
echo "$ICON_STOPPED $c stopped"
|
||||
else
|
||||
error "Failed to stop local $c"
|
||||
fi
|
||||
elif [[ "$STATUS" == "false" ]]; then
|
||||
echo "$ICON_NOT_RUNNING $c is not running, skipping"
|
||||
else
|
||||
log "$c not found locally — skipping"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -549,10 +585,10 @@ stop_containers() {
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
start_containers() {
|
||||
if [[ ${#RUNNING_CONTAINERS[@]} -eq 0 ]]; then
|
||||
log "No containers to restart."
|
||||
log "No remote containers to restart."
|
||||
return
|
||||
fi
|
||||
info "Starting containers..."
|
||||
info "Starting remote containers..."
|
||||
for c in "${RUNNING_CONTAINERS[@]}"; do
|
||||
[[ -z "$c" ]] && continue
|
||||
local needs_delay=false
|
||||
@@ -564,10 +600,41 @@ start_containers() {
|
||||
sleep "$CONTAINER_DELAY"
|
||||
fi
|
||||
echo "$ICON_START Starting $c..."
|
||||
if ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" "docker start $c" >/dev/null; then
|
||||
if ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" "docker start $c" >/dev/null 2>&1; then
|
||||
echo "$ICON_STARTED $c started"
|
||||
else
|
||||
error "Failed to start $c"
|
||||
error "Failed to start $c — start manually if needed"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# CONTAINER MANAGEMENT — START LOCAL
|
||||
# Restarts only containers tracked in LOCAL_RUNNING_CONTAINERS.
|
||||
# Respects DELAYED_CONTAINERS and CONTAINER_DELAY same as remote start.
|
||||
# If container not found → skipped gracefully.
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
start_local_containers() {
|
||||
if [[ ${#LOCAL_RUNNING_CONTAINERS[@]} -eq 0 ]]; then
|
||||
log "No local containers to restart."
|
||||
return
|
||||
fi
|
||||
info "Starting local containers..."
|
||||
for c in "${LOCAL_RUNNING_CONTAINERS[@]}"; do
|
||||
[[ -z "$c" ]] && continue
|
||||
local needs_delay=false
|
||||
for d in "${DELAYED_CONTAINERS[@]}"; do
|
||||
[[ "$c" == "$d" ]] && needs_delay=true && break
|
||||
done
|
||||
if [[ "$needs_delay" == true ]]; then
|
||||
info "Waiting ${CONTAINER_DELAY}s before starting local $c..."
|
||||
sleep "$CONTAINER_DELAY"
|
||||
fi
|
||||
echo "$ICON_START Starting local $c..."
|
||||
if docker start "$c" >/dev/null 2>&1; then
|
||||
echo "$ICON_STARTED $c started"
|
||||
else
|
||||
error "Failed to start local $c — start manually if needed"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user