-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreload_nginx.sh
More file actions
executable file
·82 lines (67 loc) · 2.38 KB
/
reload_nginx.sh
File metadata and controls
executable file
·82 lines (67 loc) · 2.38 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
#!/bin/bash
# reload_nginx.sh - Reloads user nginx after deploying latest config from template
# Now calls deploy_nginx.sh first. Uses centralized .env for model configuration.
# Uses ~/llm-serving symlink (setup-llama.sh). Zero-sudo, all user-level.
# All functions include error handling.
set -e
# Load configuration from .env (centralized model settings)
load_env() {
local env_file="$(dirname "${BASH_SOURCE[0]}")/.env"
if [[ -f "$env_file" ]]; then
set -a
# shellcheck source=.env
source "$env_file"
set +a
fi
}
load_env
# ─────────────────────────────────────────────
# ERROR HANDLING
# ─────────────────────────────────────────────
error() {
echo "❌ ERROR: $1" >&2
exit 1
}
success() {
echo "✅ $1"
}
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Function to deploy config before reload
deploy_config() {
if [[ -x ./deploy_nginx.sh ]]; then
log "Deploying latest nginx config from template..."
./deploy_nginx.sh || error "deploy_nginx.sh failed"
success "Config deployed from template (llama_backends, env-based API key)"
else
error "deploy_nginx.sh not found or not executable"
fi
}
# Function to reload nginx
reload_nginx() {
local nginx_config
local pid_dir
nginx_config="$HOME/llm-serving/nginx/user-nginx.conf"
pid_dir="/run/user/$(id -u)/nginx"
log "Reloading user-level nginx (zero-sudo via ~/llm-serving symlink)..."
# Ensure runtime dir
mkdir -p "$pid_dir" || error "Failed to create nginx runtime dir"
# Test config
if command -v nginx >/dev/null 2>&1; then
nginx -t -c "$nginx_config" -p "$pid_dir" || error "Nginx config test failed"
else
log "WARNING: nginx command not found, skipping syntax test"
fi
# Reload
nginx -s reload -c "$nginx_config" -p "$pid_dir" 2>/dev/null || \
error "Failed to reload nginx. Check if running with: systemctl --user status user-nginx"
success "Nginx reloaded successfully with dual-mode config (model: ${MODEL_NAME:-Unknown}, alias: coder)"
}
# Main
main() {
deploy_config
reload_nginx
success "Reload complete. Project simplified to dual-node ${MODEL_NAME:-Unknown} only."
}
main "$@"