mirror of
https://github.com/DeNNiiInc/Advanced-Smtp-Tester.git
synced 2026-04-17 17:35:59 +00:00
Add deployment scripts and config
This commit is contained in:
50
scripts/setup-server.sh
Normal file
50
scripts/setup-server.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
APP_NAME="Advanced-Smtp-Tester"
|
||||
APP_DIR="/var/www/$APP_NAME"
|
||||
|
||||
echo "🚀 Starting Server Setup for $APP_NAME..."
|
||||
|
||||
# 1. Install Dependencies
|
||||
echo "📦 Installing system dependencies..."
|
||||
apt-get update
|
||||
# Note: nodejs and npm should be present in the TurnKey Node.js template
|
||||
apt-get install -y git nginx curl build-essential
|
||||
|
||||
# Install PM2 globally if not exists
|
||||
if ! command -v pm2 &> /dev/null; then
|
||||
echo "📦 Installing PM2..."
|
||||
npm install -g pm2
|
||||
fi
|
||||
|
||||
# 2. Setup Nginx
|
||||
echo "⚙️ Configuring Nginx..."
|
||||
cp "$APP_DIR/config/nginx.conf.template" "/etc/nginx/sites-available/$APP_NAME"
|
||||
# Remove default site if exists
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
rm -f /etc/nginx/sites-enabled/nodejs # Common in TurnKey
|
||||
# Enable site
|
||||
ln -sf "/etc/nginx/sites-available/$APP_NAME" "/etc/nginx/sites-enabled/"
|
||||
# Test and Reload
|
||||
nginx -t && systemctl reload nginx
|
||||
|
||||
# 3. Setup PM2
|
||||
echo "⚙️ Configuring PM2..."
|
||||
cd "$APP_DIR"
|
||||
pm2 start ecosystem.config.js
|
||||
pm2 save
|
||||
pm2 startup systemd -u root --hp /root
|
||||
|
||||
# 4. Setup Cron Job for Auto-Sync (Every 5 minutes)
|
||||
echo "⏰ Setting up Auto-Sync Cron Job..."
|
||||
SCRIPT_PATH="$APP_DIR/scripts/sync-and-restart.sh"
|
||||
chmod +x "$SCRIPT_PATH"
|
||||
|
||||
# Add to crontab if not already there
|
||||
(crontab -l 2>/dev/null; echo "*/5 * * * * $SCRIPT_PATH") | awk '!x[$0]++' | crontab -
|
||||
|
||||
echo "✅ Setup Complete! Application is running and auto-sync is enabled."
|
||||
echo "🌐 Access your app at http://<YOUR_SERVER_IP>"
|
||||
44
scripts/sync-and-restart.sh
Normal file
44
scripts/sync-and-restart.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
APP_DIR="/var/www/Advanced-Smtp-Tester"
|
||||
LOG_FILE="/var/log/smtp-tester-sync.log"
|
||||
|
||||
# Navigate to app directory
|
||||
cd "$APP_DIR" || exit 1
|
||||
|
||||
# Log function
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Fetch latest changes
|
||||
git fetch origin
|
||||
|
||||
# Check if there are changes
|
||||
HEADHASH=$(git rev-parse HEAD)
|
||||
UPSTREAMHASH=$(git rev-parse origin/main)
|
||||
|
||||
if [ "$HEADHASH" != "$UPSTREAMHASH" ]; then
|
||||
log "Changes detected. Updating..."
|
||||
|
||||
# Pull changes
|
||||
git pull origin main >> "$LOG_FILE" 2>&1
|
||||
|
||||
# Check if package.json changed
|
||||
if git diff --name-only "$HEADHASH" "$UPSTREAMHASH" | grep "package.json"; then
|
||||
log "package.json changed. Installing dependencies..."
|
||||
npm install >> "$LOG_FILE" 2>&1
|
||||
fi
|
||||
|
||||
# Restart application
|
||||
log "Restarting application..."
|
||||
pm2 reload all >> "$LOG_FILE" 2>&1
|
||||
|
||||
log "Update complete."
|
||||
else
|
||||
# Uncomment next line for verbose logging of no-changes
|
||||
# log "No changes detected."
|
||||
# echo "No changes."
|
||||
:
|
||||
fi
|
||||
Reference in New Issue
Block a user