← back to Marketing Command Center

deploy/apply-cutover.sh

41 lines

#!/usr/bin/env bash
# Apply the DW-marketing consolidation cutover on Kamatera (run AS ROOT on the box).
# Backs up the live vhost, installs the corrected config (MCC front door + public
# /reels/*.mp4 + /privacy + /terms passthroughs to the reels app :9848), tests, reloads.
# Idempotent + safe: aborts if nginx -t fails (no reload on bad config).
set -euo pipefail

SRC=/root/DW-Agents/marketing-command-center/deploy/nginx/marketing.designerwallcoverings.com.conf
BK=/root/nginx-backup-$(date +%F-%H%M%S)
mkdir -p "$BK"

echo "→ locating live vhost for marketing.designerwallcoverings.com…"
LIVE=$(grep -rl "server_name marketing.designerwallcoverings.com" /etc/nginx/sites-available /etc/nginx/conf.d 2>/dev/null | head -1 || true)
echo "  live vhost: ${LIVE:-<none — will create in sites-available>}"

if [ -n "${LIVE:-}" ]; then
  cp "$LIVE" "$BK/" && echo "  backed up live vhost → $BK/"
  DEST="$LIVE"
else
  DEST=/etc/nginx/sites-available/marketing.designerwallcoverings.com.conf
fi

echo "→ installing corrected config → $DEST"
cp "$SRC" "$DEST"
# ensure it's enabled if using sites-available/sites-enabled layout
if [ -d /etc/nginx/sites-enabled ] && [ ! -e "/etc/nginx/sites-enabled/$(basename "$DEST")" ]; then
  ln -sf "$DEST" "/etc/nginx/sites-enabled/$(basename "$DEST")" && echo "  symlinked into sites-enabled/"
fi

echo "→ nginx -t"
nginx -t

echo "→ reloading nginx"
systemctl reload nginx
echo "✓ RELOADED_OK  (backup at $BK)"

echo "→ verify (expect 200s):"
for u in /privacy /terms; do
  printf "  %s -> " "$u"; curl -s -o /dev/null -w "%{http_code}\n" "https://marketing.designerwallcoverings.com$u" || echo "curl-failed"
done