Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions scripts/recover_ib_gateway_ready.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ wait_for_ready() {
bash "${script_dir}/wait_for_ib_gateway_ready.sh" "${gateway_mode}"
}

ensure_2fa_bot_running() {
CONTAINER_NAME="${container_name}" bash "${script_dir}/ensure_2fa_bot_running.sh"
}

echo "Ensuring ${container_name} is running before readiness check."
docker compose up -d --no-build
ensure_2fa_bot_running

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not abort readiness recovery on 2FA bot startup errors

Because this script runs with set -e, calling ensure_2fa_bot_running as a required step makes the whole recovery fail whenever ensure_2fa_bot_running.sh returns non-zero (for example, if 2fa_bot.py exits immediately due to invalid/missing TOTP_SECRET while IBKR_2FA_AUTOFILL is enabled). In that case the script exits before wait_for_ready, so the health check can report failure even when the gateway API is already healthy or would recover without the bot (e.g., existing authenticated session / non-2FA path).

Useful? React with 👍 / 👎.


if wait_for_ready "${initial_wait_seconds}"; then
exit 0
Expand All @@ -44,13 +49,15 @@ fi
echo "IB gateway API was not ready; restarting ${container_name} and retrying." >&2
docker compose ps >&2 || true
docker compose restart "${container_name}"
ensure_2fa_bot_running

if wait_for_ready "${restart_wait_seconds}"; then
exit 0
fi

echo "IB gateway API is still not ready; recreating ${container_name} and retrying." >&2
docker compose up -d --force-recreate --no-build "${container_name}"
ensure_2fa_bot_running

if wait_for_ready "${recreate_wait_seconds}"; then
exit 0
Expand Down
3 changes: 3 additions & 0 deletions tests/test_gateway_recovery_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ grep -Fq 'flock -w "${lock_wait_seconds}" 9' "$recover_script"
grep -Fq 'docker compose restart "${container_name}"' "$recover_script"
grep -Fq 'docker compose up -d --force-recreate --no-build "${container_name}"' "$recover_script"
grep -Fq 'IB_GATEWAY_READY_TIMEOUT_SECONDS="${timeout_seconds}"' "$recover_script"
grep -Fq 'CONTAINER_NAME="${container_name}" bash "${script_dir}/ensure_2fa_bot_running.sh"' "$recover_script"
ensure_count="$(grep -c 'ensure_2fa_bot_running' "$recover_script")"
test "$ensure_count" -ge 4

grep -Fq 'swap_size_mib="${IB_GATEWAY_SWAP_SIZE_MIB:-2048}"' "$swap_script"
grep -Fq 'fallocate -l "${swap_size_mib}M" "${swap_file}"' "$swap_script"
Expand Down