-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_nginx.sh
More file actions
executable file
·107 lines (93 loc) · 3.69 KB
/
deploy_nginx.sh
File metadata and controls
executable file
·107 lines (93 loc) · 3.69 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
#!/bin/bash
# deploy_nginx.sh - Deploys nginx config from template using .env variables
# Uses envsubst to substitute ${DPI_FACTORY_API_KEY} into ~/llm-serving/nginx/user-nginx.conf
# Works with ~/llm-serving symlink (created by setup-llama.sh). Zero-sudo only.
# Part of simplification to dual-mode only with Gemma 4 26B A4B IT (coder alias)
set -e
# ─────────────────────────────────────────────
# ERROR HANDLING
# ─────────────────────────────────────────────
error() {
echo "❌ ERROR: $1" >&2
exit 1
}
success() {
echo "✅ $1"
}
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# ─────────────────────────────────────────────
# FUNCTIONS (with error handling on all)
# ─────────────────────────────────────────────
check_dependencies() {
if ! command -v envsubst >/dev/null 2>&1; then
error "envsubst is required but not found. Install gettext package."
fi
success "Dependencies checked"
}
load_env() {
local env_file="$HOME/llm-serving/.env"
if [[ ! -f "$env_file" ]]; then
env_file="./.env"
if [[ ! -f "$env_file" ]]; then
error ".env file not found. Please create .env with DPI_FACTORY_API_KEY=yourkey"
fi
fi
set -a
# shellcheck source=.env
source "$env_file"
set +a
if [[ -z "${DPI_FACTORY_API_KEY:-}" ]]; then
error "DPI_FACTORY_API_KEY is not set or empty in .env"
fi
success "Loaded environment from $env_file (DPI_FACTORY_API_KEY set)"
}
deploy_config() {
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local template="$script_dir/nginx/user-nginx.conf.template"
local output_dir="$HOME/llm-serving/nginx"
local output="$output_dir/user-nginx.conf"
if [[ ! -f "$template" ]]; then
error "Template not found at $template"
fi
mkdir -p "$output_dir" || error "Failed to create directory $output_dir"
# Perform substitution
envsubst '$DPI_FACTORY_API_KEY' < "$template" > "$output" || error "envsubst failed"
# Verify the output contains the key (basic check, not printing secret)
if grep -q "Bearer " "$output"; then
success "Config generated successfully at $output (upstream: llama_backends)"
else
error "Substitution failed - no Bearer token found in output"
fi
}
validate_config() {
local config
local pid_dir
config="$HOME/llm-serving/nginx/user-nginx.conf"
pid_dir="/run/user/$(id -u)/nginx"
if command -v nginx >/dev/null 2>&1; then
if nginx -t -c "$config" -p "$pid_dir" 2>/dev/null; then
success "Nginx config syntax is valid"
else
log "WARNING: nginx -t check skipped or failed (may need full path setup)"
fi
else
log "Note: nginx not available for syntax check"
fi
}
# ─────────────────────────────────────────────
# MAIN
# ─────────────────────────────────────────────
main() {
log "Starting nginx config deployment (dual-mode only)..."
check_dependencies
load_env
deploy_config
validate_config
success "Nginx deployment complete. Run ./reload_nginx.sh to apply changes."
echo ""
echo "Note: This supports only dual-node with model alias 'coder'"
}
main "$@"