← back to Silverleafwallpaper
scripts/rebuild-and-deploy.sh
33 lines
#!/usr/bin/env bash
# rebuild-and-deploy.sh — refresh silverleafwallpaper.com's RML- feed from the
# local dw_unified mirror and push it live. Idempotent; safe to run any time.
#
# The live server runs in STATIC MODE (admin-catalog disabled on Kamatera → it
# reads data/products.json directly), so the whole refresh is: rebuild the file,
# rsync it, pm2 restart to reload. No dw_unified.microsite_products write needed.
#
# 1. rebuild data/products.json from dw_unified (ACTIVE RML- only)
# 2. rsync it to the Kamatera site
# 3. pm2 restart so the server reloads the file + re-runs the RML niche filter
# 4. verify the live count over HTTPS
set -euo pipefail
REPO="$(cd "$(dirname "$0")/.." && pwd)"
REMOTE="/var/www/silverleafwallpaper.com"
PM2_PROC="silverleafwallpaper"
HEALTH="https://silverleafwallpaper.com/api/products?limit=1"
cd "$REPO"
echo "[$(date '+%F %T')] rebuild silver RML- feed"
node scripts/build-products.js
echo "rsync → Kamatera"
rsync -az data/products.json "kamatera:$REMOTE/data/products.json"
echo "pm2 restart + verify"
ssh kamatera "pm2 restart $PM2_PROC >/dev/null 2>&1; sleep 3"
TOTAL=$(curl -s --max-time 20 "$HEALTH" | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const j=JSON.parse(s);console.log(j.total)}catch(e){console.log("ERR")}})')
echo "[$(date '+%F %T')] live total: $TOTAL"
[ "$TOTAL" = "ERR" ] && { echo "VERIFY FAILED"; exit 1; }
echo "done."