Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 8s
nixos - Move dynu-monitor into projects/homelab/dynu-monitor - Move new-repo into projects/nixos/new-repo - Fix relative links pointing to project plans - Update root index in README.md
4.2 KiB
4.2 KiB
type, status, project, tags
| type | status | project | tags | |||||
|---|---|---|---|---|---|---|---|---|
| plan | completed | dynu-monitor |
|
🔄 High-Frequency Provider-Rotating Dynu DDNS Monitor
🎯 Motivation & Goals
The default Dynu DDNS change detection mechanism operated on a 30-minute interval and queried a single external IP discovery provider. During ISP WAN IP rotations, services on roadtotech.me remained inaccessible for extended durations before the rotation was detected.
Architectural Objectives:
- Near-Instant WAN Change Detection: Reduce the polling interval from 30 minutes to 30 seconds so that WAN rotations are detected in seconds.
- Stateful Round-Robin Provider Rotation: Query an expanded pool of 5 reputable echo providers sequentially. This distributes requests such that each provider is queried at most once every 2.5 minutes (~24 requests/hour), well within public terms of service.
- Atomic State Persistence: Save current IP and resolver rotation index to
/var/lib/dynu/state.json. - Modernized Datetime Handling: Replace deprecated
datetime.utcnow()withdatetime.now(timezone.utc).
🏛️ Architecture & Sequence
sequenceDiagram
autonumber
participant Timer as systemd.timers.dynu-monitor (30s)
participant Monitor as dynu-ip-monitor (Python)
participant State as /var/lib/dynu/state.json
participant Resolvers as IP Resolvers (Round-Robin Pool)
participant History as /var/lib/dynu/ip_history.jsonl
participant DDClient as ddclient.service
Timer->>Monitor: Trigger execution
Monitor->>State: Read last successful provider index & last IP
Monitor->>Resolvers: Query next provider (index + 1 mod N)
alt Provider succeeds
Resolvers-->>Monitor: Valid Public IPv4
Monitor->>State: Persist updated provider index
else Provider fails
Monitor->>Resolvers: Fallback to next provider in sequence
end
alt IP changed (current_ip != last_ip)
Monitor->>DDClient: systemctl start ddclient.service
DDClient-->>Monitor: DDNS record updated
Monitor->>History: Record transition event (status: success)
Monitor->>State: Update last_ip = current_ip
else IP unchanged
Monitor->>Monitor: Exit 0 (zero API overhead)
end
🛠️ Implementation Details
1. Resolver Pool & Script (hosts/server/monitor.py)
- Configured Resolver Providers:
https://api.ipify.orghttps://icanhazip.comhttps://ifconfig.me/iphttps://checkip.dynu.comhttps://wtfismyip.com/text
- State Persistence: Atomic read and write to
STATE_FILE(/var/lib/dynu/state.json):{ "last_provider_index": 2, "last_ip": "186.168.137.93" } - Fallback Ring Buffer: Circular traversal starting at
(last_provider_index + 1) % len(PROVIDERS)with automatic fallback to next providers upon timeout or connection errors.
2. Declarative Systemd Units (hosts/server/dynu.nix)
- Timer Configuration:
systemd.timers.dynu-monitor = { description = "Timer for Dynu DDNS Smart IP Change Monitor"; timerConfig = { OnBootSec = "10s"; OnUnitActiveSec = "30s"; AccuracySec = "1s"; Persistent = true; }; wantedBy = [ "timers.target" ]; }; - Service Environment:
systemd.services.dynu-monitor.serviceConfig.Environment = [ "STATE_FILE=/var/lib/dynu/state.json" ];
🔄 Verification & Testing
1. Flake & Derivation Builds
# Validate flake expressions
nix flake check
# Dry build server host configuration
nix build .#nixosConfigurations.server.config.system.build.toplevel --no-link
# Dry build workstation configurations
nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link
nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link
2. Runtime Verification
- Timer Frequency:
systemctl list-timers dynu-monitor.timershows active 30s recurrence. - Provider Rotation:
journalctl -u dynu-monitor.service -flogs successive queries rotating cleanly across the 5 resolvers. - State File:
/var/lib/dynu/state.jsonupdates atomically after each successful poll.