-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-dev.sh
More file actions
executable file
·84 lines (75 loc) · 3.27 KB
/
Copy pathrun-dev.sh
File metadata and controls
executable file
·84 lines (75 loc) · 3.27 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
#!/usr/bin/env bash
# run-dev.sh — start openproxy in background for local testing.
#
# Usage: ./run-dev.sh
#
# Environment overrides (all optional):
# OPENPROXY_MASTER_KEY master encryption key for the DB. If unset, a random
# one is generated for this run and stored in
# .openproxy.env so restarts keep the same DB usable.
# OPENPROXY_BIND server bind (default 0.0.0.0:8787)
# OPENPROXY_DATA_DIR where the SQLite DB lives (default ~/.openproxy)
#
# The openproxy binary now serves BOTH the OpenAI-compatible API (/v1/*,
# /admin/api/*) and the dashboard SPA (/admin/*) on the same port — the
# dashboard is embedded at compile time via rust-embed (see
# `crates/openproxy-server/src/admin_ui.rs`). There is no separate
# `openproxy-web` binary anymore; the frontend source tree lives at
# `crates/openproxy-server/web/` and is built by `pnpm build` before
# `cargo build --release -p openproxy-server`.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DATA_DIR="${OPENPROXY_DATA_DIR:-$HOME/.openproxy}"
ENV_FILE="$ROOT_DIR/.openproxy.env"
SERVER_LOG="$ROOT_DIR/openproxy.log"
SERVER_PID_FILE="$ROOT_DIR/.openproxy.pid"
mkdir -p "$DATA_DIR"
# --- Master key ---------------------------------------------------------------
# Load all env vars from .openproxy.env (if it exists).
# This picks up OAuth credentials, master key, etc.
if [ -f "$ENV_FILE" ]; then
# shellcheck disable=SC1090
. "$ENV_FILE"
fi
if [ -z "${OPENPROXY_MASTER_KEY:-}" ]; then
OPENPROXY_MASTER_KEY="$(openssl rand -base64 32)"
cat > "$ENV_FILE" <<EOF
# Generated by run-dev.sh — do not commit.
OPENPROXY_MASTER_KEY=$OPENPROXY_MASTER_KEY
EOF
echo "[run-dev] generated new OPENPROXY_MASTER_KEY (saved in $ENV_FILE)"
fi
export OPENPROXY_MASTER_KEY
# --- Paths --------------------------------------------------------------------
BIN_SERVER="$ROOT_DIR/target/release/openproxy"
SERVER_BIND="0.0.0.0:8787"
# --- Stop already running instances (idempotent) -----------------------------
if [ -f "$SERVER_PID_FILE" ]; then
old_pid="$(cat "$SERVER_PID_FILE" 2>/dev/null || true)"
if [ -n "$old_pid" ] && kill -0 "$old_pid" 2>/dev/null; then
echo "[run-dev] stopping previous process from $SERVER_PID_FILE (pid=$old_pid)"
kill "$old_pid" 2>/dev/null || true
fi
rm -f "$SERVER_PID_FILE"
fi
# --- Start server -------------------------------------------------------------
echo "[run-dev] starting server on $SERVER_BIND (log: $SERVER_LOG)"
nohup "$BIN_SERVER" >"$SERVER_LOG" 2>&1 &
SERVER_PID=$!
echo "$SERVER_PID" > "$SERVER_PID_FILE"
sleep 2
# --- Report -------------------------------------------------------------------
echo
echo "================================================================"
echo " openproxy"
echo "================================================================"
echo " server pid=$SERVER_PID http://$SERVER_BIND"
echo " data $DATA_DIR"
echo " logs $SERVER_LOG"
echo "================================================================"
echo " Try:"
echo " curl -s http://$SERVER_BIND/v1/health"
echo " curl -s http://$SERVER_BIND/v1/models"
echo " curl -s http://$SERVER_BIND/admin/api/providers"
echo " open http://$SERVER_BIND/admin"
echo "================================================================"