Add hook system
This commit is contained in:
@@ -72,3 +72,50 @@ dns-zone-list example.tld
|
||||
# Add an A record
|
||||
dns-record-add example.tld www 3600 A 192.0.2.1
|
||||
```
|
||||
|
||||
## Hooks
|
||||
|
||||
Executable scripts placed in the hooks base directory (`hooks_dir`, default
|
||||
`<etc_dir>/hooks`) are run around zone and record mutations. The tree narrows
|
||||
progressively and every level is optional:
|
||||
|
||||
```
|
||||
hooks/ -> every action and phase (zone+record, add+delete, pre+post)
|
||||
zone/ -> all zone actions/phases
|
||||
add/ -> zone add, both phases
|
||||
pre/ -> zone add, pre only
|
||||
post/ -> zone add, post only
|
||||
delete/{pre,post}/
|
||||
record/
|
||||
add/{pre,post}/
|
||||
delete/{pre,post}/
|
||||
```
|
||||
|
||||
For a given event `(kind, action, phase)` all matching hooks across every
|
||||
existing level along that event's path (`hooks/` → `hooks/<kind>/` →
|
||||
`hooks/<kind>/<action>/` → `hooks/<kind>/<action>/<phase>/`) are collected and
|
||||
run sorted by filename (run-parts style), so a numeric prefix (e.g. `50-`)
|
||||
controls execution order regardless of directory depth. A hook placed shallower
|
||||
in the tree fires for more events; distinguish the concrete event via the
|
||||
environment variables. Each hook inherits the terminal, so its stdout and stderr
|
||||
appear live and in order, and a hook may be interactive: it can print prompts and
|
||||
read the user's input from stdin. In batch mode (`-b`) stdin is redirected to
|
||||
`/dev/null`, so a hook that reads input gets an immediate EOF instead of blocking
|
||||
(hooks that prompt should guard on a tty/EOF).
|
||||
Only executable regular files are run; everything else (including the
|
||||
`zone`/`record`/`add`/`delete`/`pre`/`post` subdirectories) is skipped, and
|
||||
missing directories are no-ops.
|
||||
|
||||
Each hook receives context via environment variables:
|
||||
|
||||
* Common env: `DNSMGR_KIND` (zone|record), `DNSMGR_ACTION` (add|delete),
|
||||
`DNSMGR_PHASE` (pre|post), `DNSMGR_ZONE` (origin, no trailing dot), `DNSMGR_VIEW`.
|
||||
* Record-only env: `DNSMGR_RECORD_NAME`, `DNSMGR_RECORD_TTL`,
|
||||
`DNSMGR_RECORD_TYPE`, `DNSMGR_RECORD_VALUE` (values joined by newlines).
|
||||
* `DNSMGR_ZONE_FILE` (zone file path): set only for managed zones and not for zone add pre-hooks and not for zone delete post-hooks.
|
||||
|
||||
A `pre` hook exiting non-zero aborts the operation before any change is applied
|
||||
(exit code 190); a `post` hook failure only prints an `ERROR:` and continues.
|
||||
|
||||
Pass `-n`/`--no-hooks` to `dns-zone-add`, `dns-zone-delete`, `dns-record-add` or
|
||||
`dns-record-delete` to skip all hook execution for that run.
|
||||
|
||||
Reference in New Issue
Block a user