-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_phoenix.sh
More file actions
executable file
·91 lines (74 loc) · 2.01 KB
/
run_phoenix.sh
File metadata and controls
executable file
·91 lines (74 loc) · 2.01 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
#!/usr/bin/env bash
set -euo pipefail
# cd to repo root
cd "$(dirname "$0")"
# Find a free port in 5000-5005
PORTS=(5000 5001 5002 5003 5004 5005)
FREE_PORT=""
for p in "${PORTS[@]}"; do
if ! ss -ltnp | grep -q ":$p"; then
FREE_PORT="$p"
break
fi
done
if [[ -z "$FREE_PORT" ]]; then
echo "No free ports in 5000-5005." >&2
exit 1
fi
# Activate venv
if [[ -f ".venv/bin/activate" ]]; then
# shellcheck disable=SC1091
source .venv/bin/activate
elif [[ -f "venv/bin/activate" ]]; then
# shellcheck disable=SC1091
source venv/bin/activate
else
echo "Virtual environment not found. Please run 'uv sync' or create/activate venv first." >&2
exit 1
fi
# Ensure secrets exist
mkdir -p tmp
SECRETS_FILE="tmp/phoenix_secrets.env"
if [[ ! -f "$SECRETS_FILE" ]]; then
python - <<'PY' > "$SECRETS_FILE"
import secrets
def strong(n):
return secrets.token_urlsafe(n)
print("PHOENIX_SECRET=" + strong(48))
print("PHOENIX_DEFAULT_ADMIN_INITIAL_PASSWORD=" + strong(16))
PY
fi
# Export auth and server env
set -a
source "$SECRETS_FILE"
set +a
export PHOENIX_ENABLE_AUTH=true
export PHOENIX_HOST=0.0.0.0
export PHOENIX_PORT="$FREE_PORT"
# Persist chosen port for other processes (agent auto-detect)
echo -n "$FREE_PORT" > tmp/phoenix_port
echo "Starting Phoenix on 0.0.0.0:${FREE_PORT} (auth enabled)."
echo "Admin initial password is set via PHOENIX_DEFAULT_ADMIN_INITIAL_PASSWORD in $SECRETS_FILE"
echo "To change, edit the file and restart."
# Start Phoenix server
set +e
echo "Starting Phoenix server on port $FREE_PORT..."
# Set environment variables for Phoenix
export PHOENIX_HOST=0.0.0.0
export PHOENIX_PORT="$FREE_PORT"
# Start Phoenix using Python API
python -c "
import phoenix as px
import time
try:
print('Starting Phoenix...')
session = px.launch_app()
print(f'Phoenix started on http://0.0.0.0:$FREE_PORT')
print('Press Ctrl+C to stop...')
while True:
time.sleep(1)
except KeyboardInterrupt:
print('Phoenix stopped.')
except Exception as e:
print(f'Error: {e}')
"