refactor(homelab): restructure dynu-monitor into discussion and native Rust plan
Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 7s
Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 7s
- Remove nested dynu-monitor sub-project directory - Add discussion on DDNS polling frequency and Rust vs Python trade-offs - Establish active implementation plan for standalone Rust daemon - Update homelab README catalog and validate graph integrity
This commit is contained in:
1 parent
bb6d61712f
commit
7117a392e7
6 files changed
+153
-295
No files matched your search
@@ -22,6 +22,8 @@ Foundational inquiries, problem statements, and trade-off analyses that inform t
|
|||||||
- Analysis and file migration inventory for transferring the server definition into `homelab-core`.
|
- Analysis and file migration inventory for transferring the server definition into `homelab-core`.
|
||||||
3. [**Gitea Git Credential Helper, Protocol Trade-Offs, and Backup Architecture**](discussions/gitea-credentials-and-backup-strategy.md)
|
3. [**Gitea Git Credential Helper, Protocol Trade-Offs, and Backup Architecture**](discussions/gitea-credentials-and-backup-strategy.md)
|
||||||
- Evaluates Git credential management, SSH vs. HTTPS, and primary (Gitea) vs. backup (GitHub) topology.
|
- Evaluates Git credential management, SSH vs. HTTPS, and primary (Gitea) vs. backup (GitHub) topology.
|
||||||
|
4. [**Dynu DDNS Polling Frequency, Resolver Rotation, and Rust Migration**](discussions/dynu-monitor-polling-and-language-tradeoffs.md)
|
||||||
|
- Evaluates 30m vs. 30s polling intervals, provider rate limits, and the rationale for migrating from Python directly to a native Rust daemon.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -67,6 +69,10 @@ Phased implementation plans originating from architectural decisions:
|
|||||||
1. 🟡 [**Custom API Security Hardening & Threat Analysis**](plans/api-security-hardening.md) `[Active]`
|
1. 🟡 [**Custom API Security Hardening & Threat Analysis**](plans/api-security-hardening.md) `[Active]`
|
||||||
- Attack surface review, Authelia ForwardAuth integration, rate limiting, and JWT fail-fast validation.
|
- Attack surface review, Authelia ForwardAuth integration, rate limiting, and JWT fail-fast validation.
|
||||||
|
|
||||||
|
### 🔄 Dynamic DNS & Infrastructure Daemons
|
||||||
|
1. 🟡 [**Rust Daemon Migration Plan: Standalone `dynu-monitor`**](plans/dynu-monitor-rust-daemon.md) `[Active]`
|
||||||
|
- High-frequency 30-second polling, 5-endpoint round-robin rotation, and zero-runtime-dependency Rust daemon.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🛠️ Canonical Guides & Runbooks ("How to Use & Operate?")
|
## 🛠️ Canonical Guides & Runbooks ("How to Use & Operate?")
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
---
|
||||||
|
type: discussion
|
||||||
|
project: homelab
|
||||||
|
date: 2026-09-11
|
||||||
|
tags:
|
||||||
|
- homelab
|
||||||
|
- dynu
|
||||||
|
- ddns
|
||||||
|
- python
|
||||||
|
- rust
|
||||||
|
- architecture
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🔄 Discussion: Dynu DDNS Polling Frequency, Resolver Rotation, and Rust Migration
|
||||||
|
|
||||||
|
## 1. Problem Statement
|
||||||
|
|
||||||
|
The production Dynu dynamic DNS monitor on the server currently runs on a **30-minute systemd timer** (`OnUnitActiveSec = "30min"`) and queries a sequential fallback list of 4 external echo providers. When the residential ISP rotates the server's public WAN IPv4 address, external domains on `roadtotech.me` can remain unreachable for up to 30 minutes before the monitor detects the transition and triggers `ddclient.service`.
|
||||||
|
|
||||||
|
### Core Tension:
|
||||||
|
* **Speed of Recovery**: To minimize service downtime, the monitor should detect WAN rotations within **30 to 60 seconds**.
|
||||||
|
* **Provider Abuse & Rate Limits**: Polling a single public echo API (such as `api.ipify.org` or `icanhazip.com`) every 30 seconds yields 2,880 requests per day from a single IP, which risks temporary bans or API blocking.
|
||||||
|
* **Language & Runtime Overhead**: The current implementation is written in Python (`pkgs.writers.writePython3Bin`), invoking the full Python 3.14 interpreter and standard libraries on every execution of a headless server appliance.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Exploration: The 5-Provider Stateful Pool Prototype
|
||||||
|
|
||||||
|
On an experimental branch (`refactor/dynu-monitor`), an alternative Python prototype was designed:
|
||||||
|
* Increase systemd timer frequency to **30 seconds**.
|
||||||
|
* Distribute queries across an expanded pool of **5 external providers** (`api.ipify.org`, `icanhazip.com`, `ifconfig.me`, `checkip.dynu.com`, `wtfismyip.com`).
|
||||||
|
* Use a stateful round-robin pointer stored in `/var/lib/dynu/state.json`.
|
||||||
|
|
||||||
|
### Evaluation of the Prototype:
|
||||||
|
* **Pros**:
|
||||||
|
- Each individual provider is queried at most once every 2.5 minutes (~24 requests/hour), well within public usage guidelines.
|
||||||
|
- WAN rotations are detected in under 30 seconds.
|
||||||
|
* **Cons & Complications**:
|
||||||
|
- Requires writing local state back and forth from disk on every 30s tick.
|
||||||
|
- Python startup overhead running 2,880 times a day creates unnecessary CPU and I/O noise on a low-power home server.
|
||||||
|
- The prototype remained unmerged because maintaining complex state machines in an embedded Nix Python script is brittle.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. The Resolution: Direct Migration to a Native Rust Daemon
|
||||||
|
|
||||||
|
Rather than merging the intermediate Python rewrite into `Core`, the preferred architectural path is to migrate `dynu-monitor` directly to a lightweight, compiled **Rust daemon**.
|
||||||
|
|
||||||
|
### Why Rust?
|
||||||
|
1. **Zero Runtime Dependencies**: The compiled binary requires no Python interpreter, virtualenv, or dynamic store dependencies, aligning with the headless appliance philosophy.
|
||||||
|
2. **Minimal Footprint**: A native daemon can either run as a persistent background process with an internal async timer (`tokio`), or as an ultra-fast oneshot binary with zero startup penalty.
|
||||||
|
3. **Decoupled Architecture**: Domain logic (`IpMonitorService`) is separated from I/O mechanisms (`IpResolver`, `StateRepository`, `DdnsUpdater`) via traits, allowing comprehensive unit testing without real network or systemd calls.
|
||||||
|
4. **Hands-on Rust Engineering**: Serves as a practical project for idiomatic Rust patterns (traits, structs/enums, dependency injection, and Cargo packaging in Nix).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Architectural Invariants for the Rust Implementation
|
||||||
|
|
||||||
|
1. **Gatekeeper Pattern**: `dynu-monitor` only triggers `ddclient.service` when a public IP change is verified.
|
||||||
|
2. **Update Confirmation**: `last_ip` in `state.json` is updated **only after** `ddclient` exits successfully. A failed update preserves the previous IP so retries continue.
|
||||||
|
3. **Graceful Resolver Failover**: If the current provider in the round-robin sequence fails or times out (5s), the daemon falls back to the next provider immediately without failing the tick.
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
---
|
|
||||||
type: project
|
|
||||||
status: active
|
|
||||||
tags:
|
|
||||||
- dynu
|
|
||||||
- ddns
|
|
||||||
- rust
|
|
||||||
- python
|
|
||||||
- homelab
|
|
||||||
---
|
|
||||||
# 🔄 dynu-monitor — High-Frequency Smart DDNS Monitor
|
|
||||||
|
|
||||||
## 🎯 Project Overview
|
|
||||||
|
|
||||||
`dynu-monitor` is a lightweight, local-first dynamic DNS change detector and smart trigger daemon. It monitors the machine's public IPv4 address and triggers dynamic DNS updates (via `ddclient.service`) only when a verified IP change has occurred.
|
|
||||||
|
|
||||||
By acting as a local gatekeeper in front of the DNS updater, it prevents unnecessary API spam to DNS providers, avoids IP change detection latency, and distributes external IP lookup queries across multiple external echo services using a stateful round-robin rotation strategy.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🏛️ System Architecture
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
autonumber
|
|
||||||
participant Timer as systemd.timers.dynu-monitor (30s)
|
|
||||||
participant Monitor as dynu-ip-monitor
|
|
||||||
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 Tracks
|
|
||||||
|
|
||||||
The project spans two iterative phases:
|
|
||||||
|
|
||||||
### 1. Python / NixOS Implementation *(Completed)*
|
|
||||||
- **Status**: Completed and verified on branch `refactor/dynu-monitor`.
|
|
||||||
- **Key Features**:
|
|
||||||
- 30-second polling interval via `systemd.timers.dynu-monitor`.
|
|
||||||
- Stateful round-robin rotation across 5 public providers (`api.ipify.org`, `icanhazip.com`, `ifconfig.me`, `checkip.dynu.com`, `wtfismyip.com`).
|
|
||||||
- Atomic persistence to `/var/lib/dynu/state.json`.
|
|
||||||
- Modernized UTC timezone handling (`datetime.now(timezone.utc)`).
|
|
||||||
- **Documentation**: [**High-Frequency Provider-Rotating Monitor Plan**](plans/provider-rotating-monitor-plan.md)
|
|
||||||
|
|
||||||
### 2. Standalone Rust Binary *(Active / In Planning)*
|
|
||||||
- **Status**: Planning and domain modeling phase at `/home/kiskaadee/Projects/active/dynu-monitor`.
|
|
||||||
- **Goals**:
|
|
||||||
- Clean separation between domain orchestration (`IpMonitorService`) and external infrastructure (`IpResolver`, `StateRepository`, `DdnsUpdater`).
|
|
||||||
- Zero Python runtime dependencies for minimal footprint on headless servers.
|
|
||||||
- Comprehensive unit test coverage with dependency injection and trait mocks.
|
|
||||||
- **Documentation**: [**Rust Migration Plan & Milestones**](plans/rust-migration-plan.md)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📑 Project Documents & Plans
|
|
||||||
|
|
||||||
- [**High-Frequency Provider-Rotating Monitor Plan & Walkthrough**](plans/provider-rotating-monitor-plan.md) — Architectural design, 5-provider pool, systemd timer config, and verification results for the Python implementation.
|
|
||||||
- [**Rust Migration Plan**](plans/rust-migration-plan.md) — Architecture, domain entities, invariants, and phased milestones for the native Rust daemon.
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
---
|
|
||||||
type: plan
|
|
||||||
status: completed
|
|
||||||
project: dynu-monitor
|
|
||||||
tags:
|
|
||||||
- dynu
|
|
||||||
- ddns
|
|
||||||
- python
|
|
||||||
- nixos
|
|
||||||
- architecture
|
|
||||||
---
|
|
||||||
# 🔄 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:
|
|
||||||
1. **Near-Instant WAN Change Detection**: Reduce the polling interval from 30 minutes to **30 seconds** so that WAN rotations are detected in seconds.
|
|
||||||
2. **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.
|
|
||||||
3. **Atomic State Persistence**: Save current IP and resolver rotation index to `/var/lib/dynu/state.json`.
|
|
||||||
4. **Modernized Datetime Handling**: Replace deprecated `datetime.utcnow()` with `datetime.now(timezone.utc)`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🏛️ Architecture & Sequence
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
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**:
|
|
||||||
1. `https://api.ipify.org`
|
|
||||||
2. `https://icanhazip.com`
|
|
||||||
3. `https://ifconfig.me/ip`
|
|
||||||
4. `https://checkip.dynu.com`
|
|
||||||
5. `https://wtfismyip.com/text`
|
|
||||||
- **State Persistence**: Atomic read and write to `STATE_FILE` (`/var/lib/dynu/state.json`):
|
|
||||||
```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**:
|
|
||||||
```nix
|
|
||||||
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**:
|
|
||||||
```nix
|
|
||||||
systemd.services.dynu-monitor.serviceConfig.Environment = [
|
|
||||||
"STATE_FILE=/var/lib/dynu/state.json"
|
|
||||||
];
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔄 Verification & Testing
|
|
||||||
|
|
||||||
### 1. Flake & Derivation Builds
|
|
||||||
```bash
|
|
||||||
# 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.timer` shows active 30s recurrence.
|
|
||||||
- **Provider Rotation**: `journalctl -u dynu-monitor.service -f` logs successive queries rotating cleanly across the 5 resolvers.
|
|
||||||
- **State File**: `/var/lib/dynu/state.json` updates atomically after each successful poll.
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
---
|
|
||||||
type: plan
|
|
||||||
status: active
|
|
||||||
project: dynu-monitor
|
|
||||||
tags:
|
|
||||||
- dynu
|
|
||||||
- ddns
|
|
||||||
- rust
|
|
||||||
- migration
|
|
||||||
---
|
|
||||||
# 🦀 Rust Migration Plan: Standalone `dynu-monitor` Daemon
|
|
||||||
|
|
||||||
## 🎯 Motivation & Objectives
|
|
||||||
|
|
||||||
While the Python implementation in `hosts/server/monitor.py` verified the core logic (30-second polling, 5-provider round-robin rotation, atomic state persistence), migrating the monitor to a native **Rust** binary provides:
|
|
||||||
|
|
||||||
1. **Zero Runtime Dependencies**: Removes Python runtime and interpreter startup overhead from headless NixOS servers.
|
|
||||||
2. **Strict Type Safety & Robust Error Handling**: Eliminates runtime type errors and unhandled exceptions using `Option<T>`, `Result<T, E>`, and custom error types.
|
|
||||||
3. **Decoupled Architecture**: Clean domain orchestration (`IpMonitorService`) abstracted from I/O mechanisms via traits for unit testing without network or systemd dependencies.
|
|
||||||
4. **Hands-on Rust Learning**: Serves as a practical project for idiomatic Rust patterns (traits, structs/enums, dependency injection, and Cargo).
|
|
||||||
|
|
||||||
**Project Location**: `/home/kiskaadee/Projects/active/dynu-monitor`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🏛️ Target Architecture
|
|
||||||
|
|
||||||
```text
|
|
||||||
┌───────────────┐
|
|
||||||
│ main.rs │
|
|
||||||
│ (Composition) │
|
|
||||||
└───────┬───────┘
|
|
||||||
│
|
|
||||||
▼
|
|
||||||
┌───────────────┐
|
|
||||||
│IpMonitorService│
|
|
||||||
│(Domain Engine)│
|
|
||||||
└───────┬───────┘
|
|
||||||
│
|
|
||||||
┌─────────────┼─────────────┐
|
|
||||||
▼ ▼ ▼
|
|
||||||
IpResolver StateRepository DdnsUpdater
|
|
||||||
│ │ │
|
|
||||||
▼ ▼ ▼
|
|
||||||
HTTP JSON systemctl
|
|
||||||
│
|
|
||||||
▼
|
|
||||||
HistoryRepository
|
|
||||||
│
|
|
||||||
▼
|
|
||||||
JSONL
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔒 Critical Invariants
|
|
||||||
|
|
||||||
1. `last_ip` strictly represents the IP address for which a DDNS update **completed successfully**.
|
|
||||||
2. Discovering a new IP does **not** update `last_ip` until `ddclient.service` exits with success.
|
|
||||||
3. A failed DDNS update preserves the previous `last_ip` in `state.json`.
|
|
||||||
4. If current IP matches `last_ip`, `ddclient.service` is never invoked.
|
|
||||||
5. Provider rotation index is persisted on every poll independently of IP changes.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📋 Implementation Milestones
|
|
||||||
|
|
||||||
### Milestone 1: Domain Core & Provider Rotation
|
|
||||||
- Define `MonitorState`, `IpDiscoveryResult`, and `HistoryEntry`.
|
|
||||||
- Implement IPv4 validation and circular round-robin provider rotation logic.
|
|
||||||
- Pure Rust standard library with zero external dependencies.
|
|
||||||
|
|
||||||
### Milestone 2: State Persistence
|
|
||||||
- Implement `StateRepository` trait and atomic JSON file writer (`state.json.tmp` -> `state.json`).
|
|
||||||
- Ensure state loading gracefully handles missing or corrupt initial state.
|
|
||||||
|
|
||||||
### Milestone 3: Application Orchestration (`IpMonitorService`)
|
|
||||||
- Implement `IpMonitorService` coordinating discovery, comparison, update dispatch, and state recording.
|
|
||||||
- Write full unit test suite with mock dependencies for resolvers and updaters.
|
|
||||||
|
|
||||||
### Milestone 4: HTTP Resolvers & Fallbacks
|
|
||||||
- Implement `IpResolver` using `reqwest` (blocking) or lightweight HTTP client.
|
|
||||||
- Implement fallback sequence across the 5 providers upon timeouts or non-200 responses.
|
|
||||||
|
|
||||||
### Milestone 5: Systemd Updater
|
|
||||||
- Implement `DdnsUpdater` invoking `systemctl start --wait ddclient.service`.
|
|
||||||
- Handle subprocess exit codes and timeout safety.
|
|
||||||
|
|
||||||
### Milestone 6: Audit History Logging
|
|
||||||
- Implement `HistoryRepository` appending structured events to `/var/lib/dynu/ip_history.jsonl`.
|
|
||||||
|
|
||||||
### Milestone 7: NixOS Integration & Packaging
|
|
||||||
- Package `dynu-monitor` via Nix flake (`pkgs.rustPlatform.buildRustPackage`).
|
|
||||||
- Replace Python `dynu-ip-monitor` derivation in `hosts/server/dynu.nix`.
|
|
||||||
- Verify 30-second timer execution and live rotation on the server.
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
---
|
||||||
|
type: plan
|
||||||
|
status: active
|
||||||
|
project: homelab
|
||||||
|
tags:
|
||||||
|
- homelab
|
||||||
|
- dynu
|
||||||
|
- ddns
|
||||||
|
- rust
|
||||||
|
- migration
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🦀 Rust Daemon Migration Plan: Standalone `dynu-monitor`
|
||||||
|
|
||||||
|
## 🎯 Goal Description
|
||||||
|
|
||||||
|
Migrate the dynamic DNS gatekeeper daemon from the current Python script to a native, statically compiled **Rust daemon** located at `/home/kiskaadee/Projects/active/dynu-monitor`.
|
||||||
|
|
||||||
|
This implementation introduces high-frequency 30-second polling and stateful round-robin resolver rotation across 5 public echo providers while eliminating Python interpreter overhead on the headless server.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏛️ Target Domain Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
┌────────────────────────┐
|
||||||
|
│ main.rs │
|
||||||
|
│ (Dependency Wiring) │
|
||||||
|
└───────────┬────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌────────────────────────┐
|
||||||
|
│ IpMonitorService │
|
||||||
|
│ (Domain Core) │
|
||||||
|
└───────────┬────────────┘
|
||||||
|
│
|
||||||
|
┌────────────────┼────────────────┐
|
||||||
|
▼ ▼ ▼
|
||||||
|
Box<dyn IpResolver> Box<dyn StateRepo> Box<dyn DdnsUpdater>
|
||||||
|
│ │ │
|
||||||
|
▼ ▼ ▼
|
||||||
|
HttpEchoPool StateFile Systemctl
|
||||||
|
(5 endpoints) (state.json) (ddclient.service)
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
HistoryFile
|
||||||
|
(ip_history.jsonl)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Non-Negotiable Invariants
|
||||||
|
|
||||||
|
1. `last_ip` strictly represents the IP address for which a DDNS update **completed successfully**.
|
||||||
|
2. Discovering a new IP does **not** update `last_ip` until `ddclient.service` exits with code 0.
|
||||||
|
3. A failed DDNS update preserves the previous `last_ip` in `state.json` to trigger a retry on the next tick.
|
||||||
|
4. Resolver queries must enforce a strict 5-second timeout to prevent stalling the monitoring loop.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗺️ Phased Implementation Milestones
|
||||||
|
|
||||||
|
### Milestone 1: Domain Entities & In-Memory Logic *(In Progress)*
|
||||||
|
- [x] Define domain types: `Ipv4Addr`, `ProviderId`, `MonitorEvent`.
|
||||||
|
- [ ] Implement `IpMonitorService` pure business logic.
|
||||||
|
- [ ] Mock traits `MockIpResolver`, `MockStateRepository`, `MockDdnsUpdater`.
|
||||||
|
- [ ] Unit tests verifying:
|
||||||
|
- No change detected $\rightarrow$ zero updater calls.
|
||||||
|
- Change detected $\rightarrow$ updater triggered $\rightarrow$ state updated.
|
||||||
|
- Updater fails $\rightarrow$ state remains unchanged.
|
||||||
|
|
||||||
|
### Milestone 2: Infrastructure Adapters (HTTP, File, Systemd)
|
||||||
|
- [ ] Implement `ReqwestIpResolver` with 5-endpoint pool (`ipify`, `icanhazip`, `ifconfig.me`, `checkip.dynu`, `wtfismyip`).
|
||||||
|
- [ ] Implement `JsonStateRepository` with atomic write (write to `.tmp` then rename).
|
||||||
|
- [ ] Implement `JsonlHistoryRepository` for append-only audit logs.
|
||||||
|
- [ ] Implement `SystemdDdnsUpdater` calling `systemctl start ddclient.service`.
|
||||||
|
|
||||||
|
### Milestone 3: Nix Packaging & Flake Integration
|
||||||
|
- [ ] Write `flake.nix` in `Projects/active/dynu-monitor` producing a static package.
|
||||||
|
- [ ] Package `dynu-monitor` into `homelab-core/nixos/modules/dynu.nix`.
|
||||||
|
- [ ] Replace `ipMonitorScript = pkgs.writers.writePython3Bin ...` with the native binary derivation.
|
||||||
|
|
||||||
|
### Milestone 4: Production Deployment & Verification
|
||||||
|
- [ ] Deploy generation via `sudo nixos-rebuild switch --flake ~/Core#server`.
|
||||||
|
- [ ] Verify 30-second timer cadence and resolver rotation in `/var/lib/dynu/state.json`.
|
||||||
|
- [ ] Verify zero memory leaks or zombie processes.
|
||||||
Reference in new issue
Block a user