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
25 changes: 25 additions & 0 deletions container_overrides/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ configure_ibc_login_dialog_timeout() {
done
}

configure_ib_gateway_vmoptions() {
local parallel_threads="${IB_GATEWAY_PARALLEL_GC_THREADS:-2}"
local conc_threads="${IB_GATEWAY_CONC_GC_THREADS:-1}"
local vmoptions

vmoptions="$(find "${TWS_PATH}" -maxdepth 2 -name ibgateway.vmoptions -type f 2>/dev/null | head -n 1 || true)"
if [ -z "$vmoptions" ]; then
echo ".> IB Gateway vmoptions file not found; skipping Java GC thread tuning"
return
fi

if grep -Eq '^-XX:ParallelGCThreads=' "$vmoptions"; then
sed -i -E "s/^-XX:ParallelGCThreads=.*/-XX:ParallelGCThreads=${parallel_threads}/" "$vmoptions"
else
printf '\n-XX:ParallelGCThreads=%s\n' "$parallel_threads" >>"$vmoptions"
fi
if grep -Eq '^-XX:ConcGCThreads=' "$vmoptions"; then
sed -i -E "s/^-XX:ConcGCThreads=.*/-XX:ConcGCThreads=${conc_threads}/" "$vmoptions"
else
printf '\n-XX:ConcGCThreads=%s\n' "$conc_threads" >>"$vmoptions"
fi
echo ".> Java GC threads set to ParallelGCThreads=${parallel_threads}, ConcGCThreads=${conc_threads}"
}

start_process() {
set_ports
apply_settings
Expand All @@ -118,6 +142,7 @@ fi
start_xvfb
setup_ssh
set_java_heap
configure_ib_gateway_vmoptions
start_vnc

if [ -n "$X_SCRIPTS" ]; then
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ services:
# -Xmx768m, which can starve sshd/Docker/guest-agent. Keep this
# configurable, but use a safer default for the current VM.
- JAVA_HEAP_SIZE=${JAVA_HEAP_SIZE:-512}
# The upstream vmoptions use 20 parallel GC threads, which is too
# aggressive for the current 2 vCPU VM and can slow Gateway startup.
- IB_GATEWAY_PARALLEL_GC_THREADS=${IB_GATEWAY_PARALLEL_GC_THREADS:-2}
- IB_GATEWAY_CONC_GC_THREADS=${IB_GATEWAY_CONC_GC_THREADS:-1}
- VNC_SERVER_PASSWORD=${VNC_SERVER_PASSWORD}
- LOGIN_TIMEOUT=600

Expand Down
2 changes: 1 addition & 1 deletion scripts/install_gateway_health_watcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cat >"$systemd_dir/ibkr-gateway-healthcheck.timer" <<EOF
Description=Run IBKR Gateway API readiness recovery every $health_interval_seconds seconds

[Timer]
OnBootSec=5min
OnActiveSec=$health_interval_seconds
OnUnitActiveSec=$health_interval_seconds
Unit=ibkr-gateway-healthcheck.service

Expand Down
6 changes: 6 additions & 0 deletions tests/test_docker_compose_ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ grep -Fq -- '-ncache_cr -noxdamage' "$run_override"
grep -Fq 'configure_ibc_login_dialog_timeout' "$run_override"
grep -Fq 'IBC_LOGIN_DIALOG_DISPLAY_TIMEOUT:-180' "$run_override"
grep -Fq 'LoginDialogDisplayTimeout=${timeout}' "$run_override"
grep -Fq 'configure_ib_gateway_vmoptions' "$run_override"
grep -Fq 'IB_GATEWAY_PARALLEL_GC_THREADS:-2' "$run_override"
grep -Fq 'IB_GATEWAY_CONC_GC_THREADS:-1' "$run_override"
grep -Fq 'Java GC threads set to ParallelGCThreads=${parallel_threads}, ConcGCThreads=${conc_threads}' "$run_override"

grep -Fq ' - "4001:4003"' "$compose_file"
grep -Fq ' - "4002:4004"' "$compose_file"
Expand All @@ -30,4 +34,6 @@ grep -Fq ' - TWOFA_TIMEOUT_ACTION=${TWOFA_TIMEOUT_ACTION:-restart}' "$compo
grep -Fq ' - RELOGIN_AFTER_TWOFA_TIMEOUT=${RELOGIN_AFTER_TWOFA_TIMEOUT:-yes}' "$compose_file"
grep -Fq ' - EXISTING_SESSION_DETECTED_ACTION=${EXISTING_SESSION_DETECTED_ACTION:-primary}' "$compose_file"
grep -Fq ' - JAVA_HEAP_SIZE=${JAVA_HEAP_SIZE:-512}' "$compose_file"
grep -Fq ' - IB_GATEWAY_PARALLEL_GC_THREADS=${IB_GATEWAY_PARALLEL_GC_THREADS:-2}' "$compose_file"
grep -Fq ' - IB_GATEWAY_CONC_GC_THREADS=${IB_GATEWAY_CONC_GC_THREADS:-1}' "$compose_file"
grep -Fq ' - ACCEPT_API_FROM_IP=${ACCEPT_API_FROM_IP:?Set ACCEPT_API_FROM_IP to your Cloud Run egress subnet or connector CIDR}' "$compose_file"
2 changes: 2 additions & 0 deletions tests/test_gateway_recovery_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ grep -Fq 'ibkr-gateway-daily-restart.timer' "$health_watcher_script"
grep -Fq 'IB_GATEWAY_HEALTHCHECK_INTERVAL_SECONDS:-300' "$health_watcher_script"
grep -Fq 'IB_GATEWAY_DAILY_RESTART_ON_CALENDAR:-*-*-* 10:30:00 UTC' "$health_watcher_script"
grep -Fq 'Environment=IB_GATEWAY_RECOVERY_LOCK_WAIT_SECONDS=0' "$health_watcher_script"
grep -Fq 'OnActiveSec=$health_interval_seconds' "$health_watcher_script"
! grep -Fq 'OnBootSec=5min' "$health_watcher_script"
grep -Fq 'enable --now ibkr-gateway-healthcheck.timer' "$health_watcher_script"
grep -Fq 'enable --now ibkr-gateway-daily-restart.timer' "$health_watcher_script"
! grep -Fq 'start ibkr-gateway-healthcheck.service' "$health_watcher_script"