Files
Connect-5/git-hooks/post-merge
DeNNiiInc 6c4aedec1d Add automatic deployment system to fix database disconnection after git pull
- Create post-merge git hook for auto service restart
- Add setup-auto-deploy.sh for easy installation
- Hook detects PM2, systemd, or manual process management
- Automatically runs npm install if package.json changes
- Eliminates need to manually run deploy.sh after updates
2025-12-22 16:09:19 +11:00

61 lines
1.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Git Post-Merge Hook - Automatically runs after git pull
# This fixes the issue where the server stops connecting to database after updates
#
# INSTALLATION:
# Copy this file to: .git/hooks/post-merge
# Make it executable: chmod +x .git/hooks/post-merge
echo "=========================================="
echo "🔄 Git Pull Detected - Running Auto-Deploy"
echo "=========================================="
# Get the project directory (where this script is)
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$PROJECT_DIR"
echo "📁 Project: $PROJECT_DIR"
# Check if package.json or package-lock.json changed
if git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | grep -q 'package'; then
echo "📦 package.json changed - updating dependencies..."
npm install
echo "✅ Dependencies updated"
else
echo " No dependency changes detected"
fi
# Restart the Node.js service
echo "🔄 Restarting Node.js service..."
# Try PM2 first (most common for Node.js apps)
if command -v pm2 &> /dev/null; then
echo " Using PM2..."
pm2 restart connect5 2>/dev/null || pm2 restart server.js 2>/dev/null || pm2 restart all
echo "✅ PM2 service restarted"
# Try systemd service
elif systemctl list-units --full --all | grep -q 'connect5.service'; then
echo " Using systemd..."
sudo systemctl restart connect5
echo "✅ Systemd service restarted"
# Try to find and restart the process manually
else
echo " Using process restart..."
# Kill existing process
pkill -f "node server.js"
sleep 2
# Start new process in background
nohup node server.js > server.log 2>&1 &
echo "✅ Process restarted"
fi
echo ""
echo "=========================================="
echo "✅ Auto-Deploy Complete!"
echo "=========================================="
echo "Server should be reconnected to database"
echo ""