logs: standardise log filenames to xamxam-{service}-{date}.log

This commit is contained in:
Pontoporeia
2026-08-24 11:34:34 +02:00
parent 7b6d79c133
commit d2cef85966
25 changed files with 442 additions and 83 deletions
+41 -15
View File
@@ -93,7 +93,7 @@ deploy: build deploy-code deploy-deps deploy-migrate
@just deploy-env
@just deploy-verify-permissions
@echo ""
@echo "ℹ️ First deploy? Also run: just deploy-backup"
@echo "ℹ️ First deploy? Also run: just deploy-all-first"
@echo ""
[group('deploy')]
@@ -294,6 +294,13 @@ deploy-verify-permissions:
err "storage/cache/rate_limit → NOT WRITABLE"
fi
# ── /var/log/xamxam writable (app log dir — NullHandler if missing) ─────────
if ssh xamxam "[ -d /var/log/xamxam ] && [ -w /var/log/xamxam ]"; then
ok "/var/log/xamxam → writable"
else
err "/var/log/xamxam → MISSING or NOT WRITABLE (run: sudo bash /tmp/deploy-server.sh)"
fi
# ── .env must be 640 ──────────────────────────────────────────────────────────
env_perm=$(ssh xamxam "stat -c '%a' /var/www/xamxam/.env 2>/dev/null" || echo "")
if [ "$env_perm" = "640" ]; then
@@ -335,6 +342,15 @@ deploy-script script_name:
@echo " sudo DEPLOY_USER=\$USER bash /tmp/{{script_name}}.sh"
@echo ""
[group('deploy')]
migrate-log-names apply="":
# Rename pre-existing logs to the xamxam-{service}-{date}.log convention.
# Dry-run by default; pass apply="--apply" to actually rename on the server.
# Requires sudo — renames files under /var/log and /var/www/xamxam/storage/logs.
rsync -v scripts/migrate-log-names.sh xamxam:/tmp/migrate-log-names.sh
ssh -t xamxam "sudo bash /tmp/migrate-log-names.sh {{apply}}"
ssh xamxam "rm -f /tmp/migrate-log-names.sh"
[group('deploy')]
deploy-backup-script:
# Upload backup-sqlite.sh to /usr/local/bin on the server (requires sudo)
@@ -353,11 +369,11 @@ deploy-backup-cron:
rsync -v deploy/xamxam-backup.cron xamxam:/tmp/xamxam-backup.cron
ssh -t xamxam "sudo install -o root -g root -m 644 /tmp/xamxam-backup.cron /etc/cron.d/xamxam-backup && rm -f /tmp/xamxam-backup.cron"
ssh -t xamxam "sudo mkdir -p /var/backups/xamxam && sudo chown www-data:www-data /var/backups/xamxam && sudo chmod 755 /var/backups/xamxam"
ssh -t xamxam "sudo touch /var/log/sqlite-backup.log && sudo chown www-data:www-data /var/log/sqlite-backup.log && sudo chmod 644 /var/log/sqlite-backup.log"
ssh -t xamxam "sudo touch /var/log/xamxam-backup-\$(date +%Y-%m-%d).log && sudo chown www-data:www-data /var/log/xamxam-backup-\$(date +%Y-%m-%d).log && sudo chmod 644 /var/log/xamxam-backup-\$(date +%Y-%m-%d).log"
@echo "✅ Cron jobs installed."
@echo " Cron file: /etc/cron.d/xamxam-backup"
@echo " Backup dir: /var/backups/xamxam"
@echo " Log file: /var/log/sqlite-backup.log"
@echo " Log file: /var/log/xamxam-backup-\$(date +%Y-%m-%d).log"
@echo ""
@echo "Verify with: just deploy-check-backup-log"
@@ -367,7 +383,7 @@ deploy-backup: deploy-backup-script deploy-backup-cron
[group('deploy')]
deploy-check-backup-log:
ssh xamxam "tail -20 /var/log/sqlite-backup.log 2>/dev/null || echo '(log file empty or missing — will be created on first cron run)'"
ssh xamxam "tail -20 /var/log/xamxam-backup-\$(date +%Y-%m-%d).log 2>/dev/null || echo '(log file empty or missing — will be created on first cron run)'"
[group('deploy')]
deploy-list-backups:
@@ -376,24 +392,33 @@ deploy-list-backups:
[group('deploy')]
deploy-cleanup-cron:
# Install cron job for orphaned draft cleanup (every 4 hours, 24h threshold).
# Install cron job for orphaned draft cleanup (every 2 days, 7-day threshold).
# Creates /etc/cron.d/xamxam-cleanup and log file on the server.
@echo "📋 Installing draft cleanup cron job…"
rsync -v scripts/cleanup-drafts.php xamxam:/var/www/xamxam/scripts/cleanup-drafts.php
ssh xamxam "chown www-data:xamxam /var/www/xamxam/scripts/cleanup-drafts.php && chmod 755 /var/www/xamxam/scripts/cleanup-drafts.php"
rsync -v scripts/cleanup-drafts.php xamxam:/tmp/cleanup-drafts.php
ssh xamxam "chmod 755 /tmp/cleanup-drafts.php"
rsync -v deploy/xamxam-cleanup.cron xamxam:/tmp/xamxam-cleanup.cron
ssh -t xamxam "sudo install -o root -g root -m 644 /tmp/xamxam-cleanup.cron /etc/cron.d/xamxam-cleanup && rm -f /tmp/xamxam-cleanup.cron"
ssh -t xamxam "sudo touch /var/log/xamxam-cleanup.log && sudo chown www-data:www-data /var/log/xamxam-cleanup.log && sudo chmod 644 /var/log/xamxam-cleanup.log"
ssh -t xamxam "sudo touch /var/log/xamxam-cleanup-\$(date +%Y-%m-%d).log && sudo chown www-data:www-data /var/log/xamxam-cleanup-\$(date +%Y-%m-%d).log && sudo chmod 644 /var/log/xamxam-cleanup-\$(date +%Y-%m-%d).log"
@echo "✅ Cleanup cron installed."
@echo " Cron file: /etc/cron.d/xamxam-cleanup"
@echo " Script: /var/www/xamxam/scripts/cleanup-drafts.php"
@echo " Log file: /var/log/xamxam-cleanup.log"
@echo " Script: /tmp/cleanup-drafts.php"
@echo " Log file: /var/log/xamxam-cleanup-\$(date +%Y-%m-%d).log"
@echo ""
@echo "Verify with: just deploy-check-cleanup-log"
[group('deploy')]
deploy-check-cleanup-log:
ssh xamxam "tail -20 /var/log/xamxam-cleanup.log 2>/dev/null || echo '(log file empty or missing — will be created on first cron run)'"
ssh xamxam "tail -20 /var/log/xamxam-cleanup-\$(date +%Y-%m-%d).log 2>/dev/null || echo '(log file empty or missing — will be created on first cron run)'"
[group('deploy')]
deploy-logrotate:
# Install /etc/logrotate.d/xamxam for app + nginx + cron logs.
@echo "📋 Installing logrotate config…"
rsync -v deploy/xamxam-logrotate xamxam:/tmp/xamxam-logrotate
ssh -t xamxam "sudo install -o root -g root -m 644 /tmp/xamxam-logrotate /etc/logrotate.d/xamxam && sudo logrotate -d /etc/logrotate.d/xamxam && rm -f /tmp/xamxam-logrotate"
@echo "✅ logrotate config installed and validated (dry-run)."
@echo " Config: /etc/logrotate.d/xamxam"
[group('deploy')]
test-restore remote_gz_path:
@@ -427,7 +452,7 @@ deploy-migrate-storage dry_run='' target_host='xamxam':
ssh {{target_host}} 'rm -f /var/www/xamxam/migrate-storage-paths.php'
[group('deploy')]
deploy-all-first: deploy deploy-backup deploy-cleanup-cron
deploy-all-first: deploy deploy-backup deploy-cleanup-cron deploy-logrotate
# One-shot: full initial deploy including backup and cleanup cron jobs.
# ============================================================================
@@ -536,7 +561,8 @@ clean:
[group('utils')]
cleanup-drafts dry_run='':
# List (dry-run) or delete orphaned draft theses older than 24h.
# Pass --no-dry-run to actually delete:
# List (dry-run) or delete orphaned draft theses older than 7 days (168h).
# Pass --no-dry-run to actually delete. Override the age with OLDER_THAN_HOURS:
# just cleanup-drafts --no-dry-run
@php -r 'define("APP_ROOT", getcwd()."/app");require APP_ROOT."/src/Database.php";$db=new Database();$dry="{{dry_run}}"!=="--no-dry-run";$res=$db->cleanupOrphanedDrafts(24,$dry);$c=count($res["candidates"]);if($c===0){echo"✅ No orphaned drafts found.\n";}elseif($dry){echo"🔍 Found {$c} orphaned draft(s):\n";foreach($res["candidates"]as$row){printf(" → #%d %s \"%s\" (submitted %s)\n",$row["id"],$row["identifier"],$row["title"],$row["submitted_at"]);}echo"\nRun \"just cleanup-drafts --no-dry-run\" to delete them.\n";}else{echo"🗑 Deleted {$res["deleted"]} orphaned draft(s).\n";}'
# OLDER_THAN_HOURS=24 just cleanup-drafts
@php scripts/cleanup-drafts.php {{dry_run}}