Files
TenerifeProp/scripts/sync-production.sh
APAW Agent Sync 578ea18e6b fix(deploy): auto-create static symlinks in sync script
Previously git reset removed symlinks (css, js, images, uploads)
which caused Nginx to return 404 for static assets.
Now deploy() recreates them after git sync.

Refs: production server, admin panel 404 fix
2026-05-14 09:29:53 +01:00

120 lines
3.1 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
echo "Fixing 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 {} \;
# Create static symlinks (Nginx expects /css, /js, /images at root)
echo "Creating static symlinks..."
cd "$PROJECT_DIR"
ln -sf public/css css 2>/dev/null || true
ln -sf public/js js 2>/dev/null || true
ln -sf public/images images 2>/dev/null || true
ln -sf public/uploads uploads 2>/dev/null || true
chown -h nero:nero css js images uploads 2>/dev/null || true
if [ -f "$PROJECT_DIR/data/tenerifeprop.db" ]; then
chmod 644 "$PROJECT_DIR/data/tenerifeprop.db"
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