Research-Stack/4-Infrastructure/storage/storage-agent.service
Brandon Schneider 99fc5d750b Add storage observer/optimizer agent (storage_agent.py)
Full Observe→Decide→Act→Emit loop for the restic + Garage + rclone stack:

- storage_agent.py: probes Garage health, restic snapshot count and dedup
  ratio (Q16_16), backup log staleness, cold-copy drift; triggers corrective
  actions (snap, cold-copy, verify, forget, offload, garage restart) based
  on Q16_16 threshold comparisons. Emits hash-chained receipts to both a
  local JSONL log (~/.cache/storage-agent.jsonl) and
  s3://research-stack/agent-receipts/ in Garage.

- storage-agent.service / storage-agent.timer: systemd units installed
  system-wide; timer fires every 15 min (RandomizedDelaySec=60). Includes
  PATH=/home/allaun/.local/bin:... so aws cli and restic are resolved.

- .git/hooks/post-commit updated: agent runs (--once) in the background
  after each restic snap, so post-commit state is always observed.

- 4-Infrastructure/AGENTS.md: full documentation of agent contract,
  receipt schema, trigger table, log paths, and usage examples.

Shim boundary: zero logic — pure subprocess calls to existing CLI tools.
No Float, no new dependencies. py_compile and live dry-run verified.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-05-18 22:32:52 -05:00

28 lines
1.1 KiB
Desktop File

[Unit]
Description=Storage agent — observe / optimize / act (restic + Garage + rclone)
After=network-online.target garage.service
Wants=network-online.target
[Service]
Type=oneshot
User=allaun
# Load Garage credentials at runtime (never committed)
EnvironmentFile=/etc/garage/garage.env
# Include user-local bin in PATH so aws cli and restic are found
Environment="PATH=/home/allaun/.local/bin:/usr/local/bin:/usr/bin:/bin"
# Map GARAGE_* → AWS_* before the Python script runs
ExecStart=/bin/bash -c '\
export AWS_ACCESS_KEY_ID="$GARAGE_ACCESS_KEY_ID"; \
export AWS_SECRET_ACCESS_KEY="$GARAGE_SECRET_ACCESS_KEY"; \
export AWS_DEFAULT_REGION=garage; \
export AWS_ENDPOINT_URL=http://localhost:3900; \
export RESTIC_REPOSITORY=s3:http://localhost:3900/research-stack; \
export RESTIC_PASSWORD_FILE=/etc/garage/restic-password; \
exec python3 "/home/allaun/Research Stack/4-Infrastructure/storage/storage_agent.py" --once'
StandardOutput=append:/home/allaun/.cache/storage-agent.log
StandardError=append:/home/allaun/.cache/storage-agent.log
TimeoutStartSec=30min