-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup_duplicate_api_server.sh
More file actions
147 lines (130 loc) Β· 3.87 KB
/
Copy pathcleanup_duplicate_api_server.sh
File metadata and controls
147 lines (130 loc) Β· 3.87 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
#!/bin/bash
# Cleanup Duplicate API Server (Port 8000)
# This script safely removes the unused port 8000 server
set -e
VPS_HOST="root@148.230.87.135"
echo "π API Server Cleanup Script"
echo "============================="
echo ""
echo "This script will:"
echo " 1. Verify port 8888 is working (your production server)"
echo " 2. Stop port 8000 server (unused duplicate)"
echo " 3. Remove unused nginx config"
echo " 4. Clean up old frontend directory"
echo ""
read -p "Continue? (y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
echo ""
echo "π Step 1: Verifying Port 8888 (Production) is Running..."
ssh ${VPS_HOST} << 'EOF'
if ps aux | grep -q "[u]vicorn.*8888"; then
echo "β
Port 8888 is running"
ps aux | grep "[u]vicorn.*8888" | head -1
else
echo "β ERROR: Port 8888 is NOT running!"
echo "This is your production server. DO NOT PROCEED."
exit 1
fi
EOF
echo ""
echo "π§ͺ Step 2: Testing Port 8888 API Response..."
ssh ${VPS_HOST} << 'EOF'
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8888/api/ui/best-plays 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "422" ]; then
echo "β
Port 8888 API responding (HTTP $HTTP_CODE)"
else
echo "β οΈ Port 8888 returned HTTP $HTTP_CODE"
echo "Proceeding anyway (may be normal if endpoint requires auth)"
fi
EOF
echo ""
echo "π Step 3: Stopping Port 8000 Server..."
ssh ${VPS_HOST} << 'EOF'
if ps aux | grep -q "[u]vicorn.*8000"; then
echo "Found port 8000 process:"
ps aux | grep "[u]vicorn.*8000"
echo ""
echo "Killing process..."
pkill -f "uvicorn.*8000" || true
sleep 2
if ps aux | grep -q "[u]vicorn.*8000"; then
echo "β οΈ Process still running, trying force kill..."
pkill -9 -f "uvicorn.*8000" || true
sleep 1
fi
if ! ps aux | grep -q "[u]vicorn.*8000"; then
echo "β
Port 8000 stopped successfully"
else
echo "β Failed to stop port 8000"
exit 1
fi
else
echo "βΉοΈ Port 8000 was not running"
fi
EOF
echo ""
echo "ποΈ Step 4: Removing Unused Nginx Config..."
ssh ${VPS_HOST} << 'EOF'
if [ -L "/etc/nginx/sites-enabled/sporttrader" ]; then
echo "Removing /etc/nginx/sites-enabled/sporttrader"
rm /etc/nginx/sites-enabled/sporttrader
echo "β
Removed symlink"
else
echo "βΉοΈ Nginx config already removed or not found"
fi
echo ""
echo "Testing nginx configuration..."
if nginx -t 2>&1 | grep -q "successful"; then
echo "β
Nginx config is valid"
echo "Reloading nginx..."
nginx -s reload
echo "β
Nginx reloaded"
else
echo "β Nginx config has errors!"
nginx -t
exit 1
fi
EOF
echo ""
echo "π§Ή Step 5: Backing Up Old Frontend Directory..."
ssh ${VPS_HOST} << 'EOF'
if [ -d "/var/www/sporttrader" ]; then
BACKUP_NAME="sporttrader.backup.$(date +%Y%m%d_%H%M%S)"
echo "Moving /var/www/sporttrader to /var/www/$BACKUP_NAME"
mv /var/www/sporttrader "/var/www/$BACKUP_NAME"
echo "β
Backed up to /var/www/$BACKUP_NAME"
else
echo "βΉοΈ Directory /var/www/sporttrader not found (already cleaned)"
fi
EOF
echo ""
echo "β
Step 6: Final Verification..."
ssh ${VPS_HOST} << 'EOF'
echo "Checking running uvicorn processes:"
ps aux | grep "[u]vicorn"
echo ""
echo "Checking nginx config:"
ls -la /etc/nginx/sites-enabled/
echo ""
echo "Testing website:"
curl -I https://max-ev-sports.com/ 2>&1 | head -5
EOF
echo ""
echo "π Cleanup Complete!"
echo ""
echo "Summary:"
echo " β
Port 8000 stopped (was unused)"
echo " β
Port 8888 still running (production)"
echo " β
Unused nginx config removed"
echo " β
Old frontend directory backed up"
echo ""
echo "Your site should now work from:"
echo " - API: Port 8888 only"
echo " - Frontend: /root/sporttrader/frontend/dist/"
echo " - Nginx: maxevsports config only"
echo ""
echo "Test your site: https://max-ev-sports.com"