Files
TenerifeProp/scripts/sync-production.sh
APAW Agent Sync 3bcc705e3b docs: add deployment guides, audit reports, and production sync scripts
- BRAINYCP_DEPLOY_GUIDE.md: complete human deployment guide
- AI_DEPLOY_CONTEXT.md: machine-readable deploy instructions for AI agents
- sync-production.sh: universal deployment script (full/quick/status/logs/backup)
- DEPLOY_PLAN.md: step-by-step deployment plan
- DEPLOY_AUDIT_REPORT.md: server audit results
- MIGRATION_AUDIT_REPORT.md: MySQL migration complexity analysis
- SERVER_AUDIT_REPORT.md: server environment audit
- Update README.md with BrainyCP deploy workflow and Git sync instructions

Refs: production server 46.175.149.131, domain tenerifeprop.es
2026-05-13 23:44:38 +01:00

124 lines
3.2 KiB
Bash

#!/bin/bash
set -e
# TenerifeProp Production Sync Script
# Usage: ./scripts/sync-production.sh [command]
# Commands:
# full - Full sync with git, install, restart (default)
# quick - Only restart server (if only .env changed)
# status - Show server status
# logs - Show logs
# backup - Backup database only
PROJECT_DIR="/home/nero/sites/tenerifeprop.es"
BUN="/home/nero/.bun/bin/bun"
SERVICE="tenerifeprop"
GITEA_URL="https://git.softuniq.eu/UniqueSoft/TenerifeProp"
cd "$PROJECT_DIR"
show_status() {
echo "=== Server Status ==="
systemctl status "$SERVICE" --no-pager
echo ""
echo "=== CPU/Memory ==="
ps aux | grep "$SERVICE" | grep -v grep
echo ""
echo "=== Disk Space ==="
df -h "$PROJECT_DIR"
echo ""
echo "=== Database Size ==="
ls -lh "$PROJECT_DIR/data/tenerifeprop.db"
echo ""
echo "=== Port Check ==="
ss -tlnp | grep :3003 || echo "Port 3003 NOT listening"
echo ""
echo "=== Healthcheck ==="
curl -s -o /dev/null -w '%{http_code}' http://localhost:3003/api/settings
echo " - /api/settings"
}
show_logs() {
journalctl -u "$SERVICE" -f --no-pager
}
backup_db() {
mkdir -p /backup/db
BACKUP_FILE="/backup/db/tenerifeprop-$(date +%Y%m%d-%H%M%S).db"
cp "$PROJECT_DIR/data/tenerifeprop.db" "$BACKUP_FILE"
echo "✅ Backup created: $BACKUP_FILE"
find /backup/db -name '*.db' -mtime +7 -delete
echo "✅ Old backups (7+ days) cleaned"
}
deploy() {
echo "=== Deploy started at $(date) ==="
# Backup database
backup_db
# Git sync
echo "=== Syncing with Gitea (production branch)... ==="
git fetch origin production
git reset --hard origin/production
# Install dependencies
"${BUN}" install --production
# Fix permissions
chown -R nero:nero "$PROJECT_DIR"
chmod 600 "$PROJECT_DIR/.env"
find "$PROJECT_DIR" -type f -not -path '*/node_modules/*' -exec chmod 644 {} \;
find "$PROJECT_DIR" -type d -exec chmod 755 {} \;
chmod 644 "$PROJECT_DIR/data/tenerifeprop.db" 2>/dev/null || true
# Restart
echo "=== Restarting $SERVICE ==="
systemctl restart "$SERVICE"
# Healthcheck
sleep 2
HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3003/api/settings)
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ Deploy successful. Healthcheck: HTTP 200"
# Tag the deploy
git tag "deploy-$(date +%Y%m%d-%H%M%S)" || true
else
echo "❌ Deploy failed. Healthcheck: HTTP $HTTP_CODE"
echo "Check logs: journalctl -u $SERVICE --no-pager -n 50"
exit 1
fi
echo "=== Deploy completed at $(date) ==="
}
quick_restart() {
echo "=== Quick restart ==="
systemctl restart "$SERVICE"
sleep 2
curl -s -o /dev/null -w '%{http_code}' http://localhost:3003/api/settings
echo " - Healthcheck"
}
case "${1:-full}" in
full)
deploy
;;
quick)
quick_restart
;;
status)
show_status
;;
logs)
show_logs
;;
backup)
backup_db
;;
*)
echo "Usage: $(basename "$0") {full|quick|status|logs|backup}"
exit 1
;;
esac