-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·92 lines (76 loc) · 2.33 KB
/
start.sh
File metadata and controls
executable file
·92 lines (76 loc) · 2.33 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
#!/bin/bash
# Start all VLog services
set -e # Exit on error
set -u # Exit on undefined variable
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Validate virtual environment exists
if [[ ! -f "$SCRIPT_DIR/venv/bin/activate" ]]; then
echo "Error: Virtual environment not found at $SCRIPT_DIR/venv"
echo "Create it with: python3 -m venv venv && source venv/bin/activate && pip install -e ."
exit 1
fi
source venv/bin/activate || {
echo "Error: Failed to activate virtual environment"
exit 1
}
# Verify Python and required modules are available
if ! python -c "from api.database import create_tables" 2>/dev/null; then
echo "Error: Failed to import api.database module"
echo "Ensure the package is installed: pip install -e ."
exit 1
fi
# Initialize database
echo "Initializing database..."
if ! python -c "from api.database import create_tables; create_tables()"; then
echo "Error: Database initialization failed"
exit 1
fi
echo "Starting VLog services..."
echo " Public site: http://localhost:9000"
echo " Admin panel: http://localhost:9001"
echo ""
echo "Press Ctrl+C to stop all services"
echo ""
# Start all services in background, but trap Ctrl+C to kill them all
cleanup() {
echo ""
echo "Shutting down services..."
kill $(jobs -p) 2>/dev/null
wait 2>/dev/null
echo "All services stopped."
exit 0
}
trap cleanup INT TERM
# Start public server (with proxy headers support for reverse proxy)
python -m uvicorn api.public:app --host 0.0.0.0 --port 9000 --proxy-headers --forwarded-allow-ips='*' &
PUBLIC_PID=$!
# Brief pause to check if it started
sleep 1
if ! kill -0 $PUBLIC_PID 2>/dev/null; then
echo "Error: Public API failed to start"
cleanup
fi
# Start admin server
python -m uvicorn api.admin:app --host 0.0.0.0 --port 9001 --proxy-headers --forwarded-allow-ips='*' &
ADMIN_PID=$!
sleep 1
if ! kill -0 $ADMIN_PID 2>/dev/null; then
echo "Error: Admin API failed to start"
cleanup
fi
# Start transcoding worker
python worker/transcoder.py &
WORKER_PID=$!
sleep 1
if ! kill -0 $WORKER_PID 2>/dev/null; then
echo "Error: Transcoding worker failed to start"
cleanup
fi
echo "Services started:"
echo " Public API PID: $PUBLIC_PID"
echo " Admin API PID: $ADMIN_PID"
echo " Worker PID: $WORKER_PID"
echo ""
# Wait for all background processes
wait