Compare commits

...
Author SHA1 Message Date
adminandClaude Opus 4.5 6882fabc95 Simplify eagle-exec by using active instance file
Instead of querying nginx config on every invocation, deploy-blue-green.sh
now writes the active instance to /opt/eagle0/.active-instance.

eagle-exec reads this file directly, with a fallback to checking running
containers if the file doesn't exist.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 10:33:02 -08:00
2 changed files with 21 additions and 27 deletions
+5
View File
@@ -35,6 +35,7 @@ WARMUP_SCRIPT="${SCRIPT_DIR}/warmup-eagle.sh"
SAVES_DIR="${APP_DIR}/saves"
FLUSH_MARKER="${SAVES_DIR}/.flush_complete"
DEPLOYMENT_IN_PROGRESS="${SAVES_DIR}/.deployment_in_progress"
ACTIVE_INSTANCE_FILE="${APP_DIR}/.active-instance"
# Colors for output
RED='\033[0;31m'
@@ -298,6 +299,10 @@ main() {
create_flush_marker "${deploy_id}" "eagle-${staging}"
log_info "[DEPLOY:${deploy_id}] Flush marker created - server will auto-invalidate stale cache"
# Write active instance file for eagle-exec helper
echo "eagle-${staging}" > "${ACTIVE_INSTANCE_FILE}"
log_info "[DEPLOY:${deploy_id}] Active instance file updated: eagle-${staging}"
# Update .env for admin service
local env_file="${APP_DIR}/.env"
if [ "$staging" = "green" ]; then
+16 -27
View File
@@ -1,43 +1,32 @@
#!/bin/bash
#
# Helper to run docker exec against the active Eagle instance.
# Automatically determines whether blue or green is active based on nginx config.
# Reads the active instance from /opt/eagle0/.active-instance (set by deploy-blue-green.sh).
#
# Usage:
# ./scripts/eagle-exec.sh printenv GEMINI_API_KEY
# ./scripts/eagle-exec.sh jcmd 1 VM.flags
# ./scripts/eagle-exec.sh sh # Get a shell
#
# Or create an alias:
# alias eagle-exec='/opt/eagle0/scripts/eagle-exec.sh'
# eagle-exec printenv GEMINI_API_KEY
# eagle-exec jcmd 1 VM.flags
# eagle-exec sh # Get a shell
#
set -euo pipefail
APP_DIR="${APP_DIR:-/opt/eagle0}"
ACTIVE_FILE="${APP_DIR}/.active-instance"
# Determine active instance from nginx config
get_active_instance() {
local backend
backend=$(docker exec nginx grep -o 'eagle-[a-z]*:40032' /etc/nginx/nginx.conf 2>/dev/null | head -1 || echo "")
if [ "$backend" = "eagle-blue:40032" ]; then
echo "eagle-blue"
elif [ "$backend" = "eagle-green:40032" ]; then
echo "eagle-green"
# Read active instance from file, with fallback
if [ -f "$ACTIVE_FILE" ]; then
ACTIVE=$(cat "$ACTIVE_FILE")
else
# Fallback: check which container is actually running
if docker inspect --format='{{.State.Running}}' eagle-blue 2>/dev/null | grep -q true; then
ACTIVE="eagle-blue"
elif docker inspect --format='{{.State.Running}}' eagle-green 2>/dev/null | grep -q true; then
ACTIVE="eagle-green"
else
# Fallback: check which container is actually running
if docker inspect --format='{{.State.Running}}' eagle-blue 2>/dev/null | grep -q true; then
echo "eagle-blue"
elif docker inspect --format='{{.State.Running}}' eagle-green 2>/dev/null | grep -q true; then
echo "eagle-green"
else
echo ""
fi
ACTIVE=""
fi
}
ACTIVE=$(get_active_instance)
fi
if [ -z "$ACTIVE" ]; then
echo "Error: No active Eagle instance found" >&2