Skip to content

feat(queue): offline operation queue for all panel integrations#62

Open
0kaba0hub wants to merge 3 commits into
mainfrom
feat/offline-queue
Open

feat(queue): offline operation queue for all panel integrations#62
0kaba0hub wants to merge 3 commits into
mainfrom
feat/offline-queue

Conversation

@0kaba0hub

Copy link
Copy Markdown
Collaborator

Problem

When the SecondDNS API is down (outage or maintenance), zone operations fired by customers' panels (Plesk/cPanel/DirectAdmin/CyberPanel hooks) were logged and dropped — zones created during our downtime never reached SecondDNS.

Solution

Local offline queue on the panel server:

  • hosting-panels/common/seconddns-queue — enqueue/flush/status tool backed by SQLite (/var/lib/seconddns/queue.db, WAL + busy_timeout; flock with a portable fallback)
  • Queue-first hooks: all six bash hooks enqueue the operation and trigger an async flush — strict FIFO is preserved even when older ops are already waiting; Plesk rename enqueues delete(old)+create(new)
  • Cron replay: /etc/cron.d/seconddns-queue flushes every minute; once the API is back everything drains automatically in order
  • Replay semantics: 409 on create / 404 on delete = success (safe duplicate delivery); 400/422 → row marked failed, drain continues; timeout/5xx/redirect → drain stops until next tick
  • CyberPanel: network errors are now caught (previously an uncaught URLError); retryable failures enqueue via the same tool
  • Monitoring: nagios_plugins/check_seconddns_queue.sh (WARN/CRIT by oldest-op age, perfdata) and zabbix_templates/seconddns_queue.yaml (items + triggers via UserParameter)
  • Installers deploy the tool + cron; uninstallers clean up; README documents the feature

Tests

hosting-panels/common/tests/test_queue.sh — self-contained suite with a scripted mock API (14 checks, all passing): enqueue persistence, drain stop on API-down, FIFO order, 409/404 duplicate semantics, hard-error isolation, status exit codes, 20-way concurrent enqueue.

Live E2E against the real maintenance switch (k8s_web scripts/maintenance-on.sh) is the next step per the test plan in seconddns/k8s_web#265.

Ref: seconddns/k8s_web#265

Zone operations from panel hooks are enqueued into a local SQLite queue
(/var/lib/seconddns/queue.db) and delivered immediately; when the
SecondDNS API is unreachable (outage or maintenance) they stay queued
and a per-minute cron replays them in strict FIFO order once the API
is back. No customer operation is lost during SecondDNS downtime.

- hosting-panels/common/seconddns-queue: enqueue/flush/status tool
  (WAL, busy_timeout, flock with portable fallback)
- all six bash hooks (plesk/cpanel/directadmin) switched to
  queue-first + async flush; plesk rename enqueues delete+create
- cyberpanel: network errors now caught; retryable failures enqueue
  via the same tool
- installers deploy the tool + /etc/cron.d/seconddns-queue;
  uninstallers clean up
- replay semantics: 409 create / 404 delete = success; 400/422 ->
  failed (does not block the queue); 5xx/timeout stop the drain
- monitoring: nagios_plugins/check_seconddns_queue.sh (-w/-c age
  thresholds) + zabbix_templates/seconddns_queue.yaml
- tests: hosting-panels/common/tests/test_queue.sh — 14 checks with
  a scripted mock API (FIFO, concurrency, all status branches)

Ref: seconddns/k8s_web#265
- new seconddns-queued (python3 stdlib): watches the queue, delivers in
  strict FIFO, exponential backoff while the API is down, configurable
  via [queue] section in /etc/seconddns.conf; --once mode for manual
  flush; systemd unit with Restart=always
- hooks are now enqueue-only (single INSERT, never block on API
  timeouts); delivery goes exclusively through the worker
- cyberpanel: add_zone/remove_zone enqueue-only (reads stay direct)
- seconddns-queue CLI simplified: enqueue/status; flush execs the
  worker --once
- installers deploy worker + unit and enable the service; no cron
- tests: 16 checks, incl. daemon-mode pickup and outage recovery

Ref: seconddns/k8s_web#265
@0kaba0hub
0kaba0hub force-pushed the feat/offline-queue branch from 434dc5e to e8095f2 Compare July 7, 2026 00:13
@0kaba0hub

Copy link
Copy Markdown
Collaborator Author

Reworked to the daemon model per review discussion:

  • seconddns-queued — python3 (stdlib-only) systemd worker, the single delivery path: watches the queue, strict FIFO, exponential backoff (backoff_minbackoff_max) while the API is down; configurable via an optional [queue] section in /etc/seconddns.conf (poll_interval, http_timeout, backoff_min, backoff_max); --once mode backs the manual seconddns-queue flush
  • Hooks are enqueue-only — a single local INSERT, so panel operations never block on API timeouts (previously up to 15 s even when healthy); no per-minute cron anywhere
  • CyberPanel unified: add_zone/remove_zone enqueue-only; list/sync reads stay direct
  • Installers deploy the worker + unit (systemctl enable --now seconddns-queued); uninstallers stop and remove it
  • Tests: 16/16 passing, including daemon-mode pickup while the API is down and automatic drain after recovery

Cross-server migration semantics (ownership check by master IP) intentionally NOT included — tracked separately in #63.

- enqueue pokes /var/lib/seconddns/queued.sock after INSERT; the worker
  wakes immediately instead of polling
- poll_interval becomes a rare fallback tick (default 60s) guarding
  lost wakeups only
- AF_UNIX ~104-byte path limit handled by binding/sending via relative
  paths; socket dir auto-created

Ref: seconddns/k8s_web#265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants