mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
chore: clean up project - remove temporary files and add quick setup guide
- Removed 18 temporary/test files (check_data.js, test_db_insert.js, etc.) - Removed old deployment scripts and debug utilities - Added setup.sh for one-command deployment - Rewrote QUICKSTART.md with comprehensive 3-step setup guide - Enhanced ecosystem.config.js with logging and restart config - Project is now clean and deployment-ready
This commit is contained in:
66
auto-sync.sh
66
auto-sync.sh
@@ -1,66 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# Auto-Sync Script - Run by Cron Every 5 Minutes
|
||||
# ============================================================================
|
||||
# This script:
|
||||
# 1. Checks for changes in Git repository
|
||||
# 2. Pulls updates if available
|
||||
# 3. Restarts the service ONLY if changes were detected
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
APP_NAME="web-page-performance-test"
|
||||
APP_DIR="/var/www/$APP_NAME"
|
||||
LOG_FILE="/var/log/$APP_NAME-autosync.log"
|
||||
|
||||
# Function to log with timestamp
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
log "========================================="
|
||||
log "Starting auto-sync check..."
|
||||
|
||||
cd "$APP_DIR" || exit 1
|
||||
|
||||
# Fetch latest from remote
|
||||
git fetch origin main 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Check if local is behind remote
|
||||
LOCAL=$(git rev-parse HEAD)
|
||||
REMOTE=$(git rev-parse origin/main)
|
||||
|
||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
||||
log "✅ Already up to date. No changes detected."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "🔄 Changes detected! Pulling updates..."
|
||||
|
||||
# Force update (overwrite local changes)
|
||||
log "⚠️ Resetting local changes to match remote..."
|
||||
git reset --hard origin/main 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Install/update dependencies if package.json changed
|
||||
if git diff --name-only $LOCAL $REMOTE | grep -q "package.json"; then
|
||||
log "📦 package.json changed. Running npm install..."
|
||||
npm install 2>&1 | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Restart the service
|
||||
log "🔄 Restarting $APP_NAME service..."
|
||||
systemctl restart "$APP_NAME" 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Wait a moment and check status
|
||||
sleep 2
|
||||
if systemctl is-active --quiet "$APP_NAME"; then
|
||||
log "✅ Service restarted successfully!"
|
||||
else
|
||||
log "❌ WARNING: Service may have failed to start!"
|
||||
systemctl status "$APP_NAME" --no-pager 2>&1 | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
log "✅ Auto-sync completed!"
|
||||
log "========================================="
|
||||
Reference in New Issue
Block a user