-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_server.sh
More file actions
executable file
·152 lines (123 loc) · 3.96 KB
/
start_server.sh
File metadata and controls
executable file
·152 lines (123 loc) · 3.96 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# VNC-Perplexity API Server Startup Script
# Usage: ./start_server.sh
set -e # Exit on any error
# Create a lock file to prevent concurrent execution
LOCKFILE="/tmp/vnc_perplexity_server.lock"
LOCKFD=99
# Lock function
_lock() {
flock -$1 $LOCKFD
}
# Unlock function
_unlock() {
flock -u $LOCKFD
}
# Create lock file
eval "exec $LOCKFD>$LOCKFILE"
# Try to acquire exclusive lock with timeout
if ! _lock "xn"; then
echo -e "\033[0;31m[ERROR]\033[0m Another instance of VNC-Perplexity server is already running"
echo -e "\033[0;31m[ERROR]\033[0m Please wait for it to complete or remove $LOCKFILE if it's stale"
exit 1
fi
# Enhanced cleanup: Remove lock file and kill processes on exit
_cleanup() {
echo -e "\033[0;33m[CLEANUP]\033[0m Shutting down server..."
# Kill any uvicorn processes
pkill -f "uvicorn.*main:app" 2>/dev/null || true
# Kill any browser processes that might be running
pkill -f "firefox.*perplexity" 2>/dev/null || true
pkill -f "chromium.*perplexity" 2>/dev/null || true
# Kill VNC processes if running
pkill -f "Xvfb.*:99" 2>/dev/null || true
pkill -f "x11vnc.*:99" 2>/dev/null || true
# Clean up temporary files
rm -f /tmp/vnc_*.pid 2>/dev/null || true
rm -f /tmp/.X99-lock 2>/dev/null || true
_unlock
rm -f "$LOCKFILE"
echo -e "\033[0;33m[CLEANUP]\033[0m Server shutdown complete"
}
trap _cleanup EXIT INT TERM
echo "🚀 Starting VNC-Perplexity API Server"
echo "======================================"
# Change to server directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if virtual environment exists
if [ ! -d "venv" ]; then
print_info "Creating virtual environment..."
python -m venv venv
fi
# Activate virtual environment
print_info "Activating virtual environment..."
source venv/bin/activate
# Install dependencies
print_info "Installing dependencies..."
if pip install -r requirements.txt; then
print_success "Dependencies installed successfully"
else
print_error "Failed to install dependencies"
exit 1
fi
# Make scripts executable
chmod +x scripts/*.sh 2>/dev/null || true
# Create necessary directories
mkdir -p temp logs
# Check for any existing server processes and kill them
print_info "Checking for existing server processes..."
if pgrep -f "uvicorn.*main:app" > /dev/null; then
print_warning "Killing existing server processes..."
pkill -f "uvicorn.*main:app" || true
sleep 2
fi
# Kill any existing browser processes
if pgrep -f "firefox.*perplexity" > /dev/null || pgrep -f "chromium.*perplexity" > /dev/null; then
print_warning "Killing existing browser processes..."
pkill -f "firefox.*perplexity" 2>/dev/null || true
pkill -f "chromium.*perplexity" 2>/dev/null || true
sleep 2
fi
echo ""
print_success "Setup complete!"
echo ""
print_info "🔧 Available commands:"
echo " - Start server: python main.py"
echo " - Run tests: python -m pytest tests/ -v"
echo " - Health check: curl http://localhost:8000/health"
echo ""
print_info "📖 API Endpoints:"
echo " - OpenAI: POST http://localhost:8000/v1/chat/completions"
echo " - Anthropic: POST http://localhost:8000/v1/messages"
echo " - Models: GET http://localhost:8000/v1/models"
echo " - Status: GET http://localhost:8000/status"
echo ""
# Ask if user wants to start the server
read -p "🚀 Start the server now? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "Starting server on http://0.0.0.0:8000"
print_warning "Press Ctrl+C to stop the server and clean up all processes"
echo ""
python main.py
fi