-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplete-pm2-restart.sh
More file actions
90 lines (73 loc) · 2.31 KB
/
Copy pathcomplete-pm2-restart.sh
File metadata and controls
90 lines (73 loc) · 2.31 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
#!/bin/bash
# Complete PM2 restart to ensure env vars are loaded
echo "🔄 Complete PM2 Restart (Force Reload Environment)"
echo "=================================================="
echo ""
# Backup PM2 config
echo "📋 Current PM2 Status:"
pm2 list | grep stairs-backend
echo ""
# Get backend directory
BACKEND_DIR="/root/stairs-new/backend"
if [ ! -d "$BACKEND_DIR" ]; then
echo "❌ Backend directory not found"
exit 1
fi
# Get package.json start script
cd "$BACKEND_DIR"
if [ -f "package.json" ]; then
START_CMD=$(grep -A 5 '"scripts"' package.json | grep '"start"' | cut -d'"' -f4)
echo "📋 Start command from package.json: $START_CMD"
else
START_CMD="node src/index.js"
echo "📋 Using default start command: $START_CMD"
fi
echo ""
read -p "This will delete and recreate the PM2 process. Continue? (y/n): " CONFIRM
if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then
echo "Cancelled."
exit 0
fi
# Stop and delete
echo ""
echo "🛑 Stopping and deleting stairs-backend..."
pm2 delete stairs-backend 2>/dev/null || true
# Wait a moment
sleep 2
# Start fresh
echo "🚀 Starting stairs-backend fresh..."
if [[ "$START_CMD" == *"npm"* ]]; then
# Extract npm script
NPM_SCRIPT=$(echo "$START_CMD" | sed 's/npm //' | sed 's/--.*//')
pm2 start npm --name stairs-backend -- run "$NPM_SCRIPT"
else
pm2 start "$START_CMD" --name stairs-backend
fi
# Wait for startup
echo ""
echo "⏳ Waiting 5 seconds for backend to start..."
sleep 5
# Verify
echo ""
echo "📋 New PM2 Status:"
pm2 list | grep stairs-backend
# Test
echo ""
echo "🧪 Testing endpoint..."
TEST_RESPONSE=$(curl -s "http://localhost:5000/api/maps/places/autocomplete?input=test" 2>&1)
if echo "$TEST_RESPONSE" | grep -q '"status":"OK"'; then
echo " ✅ Endpoint working! Key is valid."
elif echo "$TEST_RESPONSE" | grep -q "expired"; then
echo " ❌ Still expired - the key itself is expired in Google Cloud Console"
echo " → Create a new key in Google Cloud Console"
else
ERROR=$(echo "$TEST_RESPONSE" | grep -o '"error_message":"[^"]*"' | cut -d'"' -f4 || echo "Unknown")
echo " ❌ Error: $ERROR"
fi
echo ""
echo "📋 Recent logs:"
pm2 logs stairs-backend --lines 10 --nostream 2>/dev/null | tail -5
echo ""
echo "=================================================="
echo "✅ Done!"
echo ""