-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
78 lines (64 loc) · 1.72 KB
/
deploy.sh
File metadata and controls
78 lines (64 loc) · 1.72 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
#!/bin/bash
set -e
echo "Starting deployment..."
echo "Loading Node.js..."
export NVM_DIR=~/.nvm
if [ -s "$NVM_DIR/nvm.sh" ]; then
source ~/.nvm/nvm.sh
echo "Node.js $(node --version) loaded"
else
echo "ERROR: NVM not found or not properly installed"
exit 1
fi
echo "Navigating to project directory..."
if ! cd /var/www/quote-share; then
echo "ERROR: /var/www/quote-share directory not found"
exit 1
fi
if [ ! -d ".git" ]; then
echo "ERROR: Not a git repository"
exit 1
fi
echo "Fetching latest code..."
if ! git fetch origin; then
echo "ERROR: Unable to fetch from remote repository"
exit 1
fi
if ! git reset --hard origin/master; then
echo "ERROR: Unable to reset to origin/master"
exit 1
fi
echo "Updated to: $(git log -1 --oneline)"
if [ ! -f "package.json" ]; then
echo "ERROR: package.json file not found"
exit 1
fi
echo "Installing dependencies..."
if ! npm install; then
echo "ERROR: Dependency installation failed"
exit 1
fi
echo "Building project..."
if ! npm run build; then
echo "ERROR: Application build failed"
exit 1
fi
echo "Restarting application..."
if pm2 restart quote-share 2>/dev/null; then
echo "Application restarted successfully"
else
echo "Starting new PM2 process..."
if ! pm2 start npm --name quote-share -- run start -- -p 3011; then
echo "ERROR: Unable to start PM2 process"
exit 1
fi
if ! pm2 save; then
echo "WARNING: PM2 save failed - process may not survive server restart"
fi
echo "New PM2 process started successfully"
fi
if ! pm2 list | grep -q "quote-share.*online"; then
echo "ERROR: Application is not running after deployment"
exit 1
fi
echo "Deployment completed successfully"