-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.command
More file actions
executable file
·135 lines (115 loc) · 3.57 KB
/
Copy pathstart.command
File metadata and controls
executable file
·135 lines (115 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/zsh
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
VENV_PYTHON="$ROOT/.venv/bin/python"
if [[ -x "$VENV_PYTHON" ]]; then
PYTHON="$VENV_PYTHON"
else
PYTHON="$(command -v python3)"
fi
cleanup() {
"$PYTHON" "$ROOT/src/manage_dashboards.py" stop-all >/dev/null 2>&1 || true
}
close_terminal_window_if_needed() {
if [[ "${TERM_PROGRAM:-}" != "Apple_Terminal" ]]; then
return
fi
local tty_device
tty_device="$(tty 2>/dev/null || true)"
if [[ -z "$tty_device" || "$tty_device" == "not a tty" ]]; then
return
fi
osascript >/dev/null 2>&1 <<EOF || true
tell application "Terminal"
set targetTTY to "$tty_device"
repeat with w in windows
repeat with t in tabs of w
if tty of t is targetTTY then
close w
return
end if
end repeat
end repeat
end tell
EOF
}
wait_for_http() {
local port="$1"
local label="$2"
local attempt=0
local max_attempts=120
echo "Waiting for ${label} to respond on port ${port}..."
while (( attempt < max_attempts )); do
if curl --silent --fail --max-time 1 "http://127.0.0.1:${port}" >/dev/null 2>&1; then
echo "${label} is ready."
return 0
fi
attempt=$((attempt + 1))
sleep 0.5
done
echo "Timed out waiting for ${label} on port ${port}."
return 1
}
trap cleanup EXIT INT TERM
cd "$ROOT"
START_DASHBOARD="${1:-overview}"
case "$START_DASHBOARD" in
overview)
DASHBOARD_LABEL="Overview"
DASHBOARD_PORT=8601
;;
profile_lookup)
DASHBOARD_LABEL="Youth Profiles"
DASHBOARD_PORT=8602
;;
ai_assistant)
DASHBOARD_LABEL="AI Assistant"
DASHBOARD_PORT=8603
;;
caseworker_dashboard)
DASHBOARD_LABEL="Caseworker Dashboard"
DASHBOARD_PORT=8604
;;
youth_dashboard)
DASHBOARD_LABEL="Youth Dashboard"
DASHBOARD_PORT=8605
;;
*)
echo "Unknown dashboard key: $START_DASHBOARD"
echo "Valid options: overview, profile_lookup, ai_assistant, caseworker_dashboard, youth_dashboard"
exit 1
;;
esac
echo "Running schema migration..."
"$PYTHON" src/migrate_database_schema.py --database database/future_path.db
echo "Running data pipeline..."
"$PYTHON" src/run_data_pipeline.py
echo "Stopping any stale dashboard servers..."
"$PYTHON" src/manage_dashboards.py stop-all >/dev/null 2>&1 || true
echo "Starting all dashboards..."
"$PYTHON" src/manage_dashboards.py start overview
"$PYTHON" src/manage_dashboards.py start profile_lookup
"$PYTHON" src/manage_dashboards.py start ai_assistant
"$PYTHON" src/manage_dashboards.py start caseworker_dashboard
"$PYTHON" src/manage_dashboards.py start youth_dashboard
wait_for_http 8601 "Overview"
wait_for_http 8602 "Youth Profiles"
wait_for_http 8603 "AI Assistant"
wait_for_http 8604 "Caseworker Dashboard"
wait_for_http 8605 "Youth Dashboard"
echo
echo "Future Path is running."
echo "Overview: http://localhost:8601"
echo "Youth Profiles: http://localhost:8602"
echo "AI Assistant: http://localhost:8603"
echo "Caseworker Dashboard: http://localhost:8604"
echo "Youth Dashboard: http://localhost:8605"
echo "All dashboards stay running so switching is instant."
echo "Servers auto-stop after all dashboard tabs are closed."
echo
echo "Press Ctrl+C here to stop all Future Path dashboard servers."
# Open only the selected dashboard so a single dashboard tab is visible at a time.
# All servers stay running in the background; in-app navigation reuses this same tab.
open "http://localhost:${DASHBOARD_PORT}" >/dev/null 2>&1 || true
"$PYTHON" src/dashboard_idle_watcher.py --idle-seconds 20 --startup-grace-seconds 45
close_terminal_window_if_needed