FABRIC/scripts/setup-fabric-prune.sh
jedarden 455da572a8 feat(retention): add systemd timer for automatic NEEDLE log pruning
Add systemd timer and service for daily log pruning at 03:00 UTC. Includes
manual prune API endpoint, setup script, and updated documentation.

## Changes
- Add `fabric-prune.service` - systemd oneshot service for log pruning
- Add `fabric-prune.timer` - daily timer (03:00 UTC) with persistent=true
- Add `POST /api/retention/prune` - manual prune trigger with auth
- Add `scripts/setup-fabric-prune.sh` - one-shot timer installer
- Update `CLAUDE.md` - document retention policy and usage

## Retention Policy
- `archiveAfterDays: 3` - files older than 3d → archive/
- `maxAgeDays: 7` - files older than 7d → delete (safety net)
- `archiveRetentionDays: 30` - archives older than 30d → delete

## Integration
- Emits `mend.logs_pruned` events to `fabric-mend.jsonl`
- FABRIC DirectoryTailer auto-discovers events
- `/api/retention` endpoint shows current state and last prune

Resolves bd-ch6.2

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 16:22:16 -04:00

27 lines
934 B
Bash
Executable file

#!/bin/bash
# Setup FABRIC log pruning systemd timer
# Run: ./scripts/setup-fabric-prune.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
echo "==> Installing fabric-prune systemd timer..."
# Create symlinks in ~/.config/systemd/user/
mkdir -p ~/.config/systemd/user
ln -sf "$REPO_ROOT/scripts/fabric-prune.service" ~/.config/systemd/user/fabric-prune.service
ln -sf "$REPO_ROOT/scripts/fabric-prune.timer" ~/.config/systemd/user/fabric-prune.timer
# Reload systemd daemon
systemctl --user daemon-reload
# Enable and start the timer
systemctl --user enable fabric-prune.timer
systemctl --user start fabric-prune.timer
echo "==> Timer installed and enabled!"
echo " Check status: systemctl --user status fabric-prune.timer"
echo " View logs: journalctl --user -u fabric-prune.service"
echo " Next run: systemctl --user list-timers fabric-prune.timer"