From f788037bfb9e4e1a5c72558156d309b9cdefc3b0 Mon Sep 17 00:00:00 2001 From: clawbot Date: Fri, 20 Mar 2026 06:56:09 +0100 Subject: [PATCH] config: use /var/lib/dnswatcher as default data directory (#89) Closes [issue #88](https://git.eeqj.de/sneak/dnswatcher/issues/88). Changes the default `DNSWATCHER_DATA_DIR` from the relative path `./data` to the absolute path `/var/lib/dnswatcher`, following the [Filesystem Hierarchy Standard](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s08.html) convention for variable application state data. ## Changes - **`internal/config/config.go`**: Changed the Viper default for `DATA_DIR` from `"./data"` to `"/var/lib/"+name`, where `name` is the application name ("dnswatcher"). This makes the default derived from the app name rather than hardcoded. - **`internal/config/config_test.go`**: Updated `TestNew_DefaultValues` and `TestStatePath` to expect the new absolute default. - **`README.md`**: Updated the environment variable table and `.env` example to show `/var/lib/dnswatcher` as the default. The Dockerfile already set `ENV DNSWATCHER_DATA_DIR=/var/lib/dnswatcher` explicitly, so Docker deployments are unaffected. This change makes the code default consistent with the Docker configuration. `docker build .` passes all checks (fmt, lint, tests, build). Co-authored-by: user Reviewed-on: https://git.eeqj.de/sneak/dnswatcher/pulls/89 Co-authored-by: clawbot Co-committed-by: clawbot --- README.md | 4 ++-- internal/config/config.go | 2 +- internal/config/config_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 94d45d9..c4e6a6d 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,7 @@ the following precedence (highest to lowest): |---------------------------------|--------------------------------------------|-------------| | `PORT` | HTTP listen port | `8080` | | `DNSWATCHER_DEBUG` | Enable debug logging | `false` | -| `DNSWATCHER_DATA_DIR` | Directory for state file | `./data` | +| `DNSWATCHER_DATA_DIR` | Directory for state file | `/var/lib/dnswatcher` | | `DNSWATCHER_TARGETS` | Comma-separated DNS names (auto-classified via PSL) | `""` | | `DNSWATCHER_SLACK_WEBHOOK` | Slack incoming webhook URL | `""` | | `DNSWATCHER_MATTERMOST_WEBHOOK` | Mattermost incoming webhook URL | `""` | @@ -244,7 +244,7 @@ list of DNS names before starting. ```sh PORT=8080 DNSWATCHER_DEBUG=false -DNSWATCHER_DATA_DIR=./data +DNSWATCHER_DATA_DIR=/var/lib/dnswatcher DNSWATCHER_TARGETS=example.com,example.org,www.example.com,api.example.com,mail.example.org DNSWATCHER_SLACK_WEBHOOK=https://hooks.slack.com/services/T.../B.../xxx DNSWATCHER_MATTERMOST_WEBHOOK=https://mattermost.example.com/hooks/xxx diff --git a/internal/config/config.go b/internal/config/config.go index 3e6df75..264b90b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -94,7 +94,7 @@ func setupViper(name string) { viper.SetDefault("PORT", defaultPort) viper.SetDefault("DEBUG", false) - viper.SetDefault("DATA_DIR", "./data") + viper.SetDefault("DATA_DIR", "/var/lib/"+name) viper.SetDefault("TARGETS", "") viper.SetDefault("SLACK_WEBHOOK", "") viper.SetDefault("MATTERMOST_WEBHOOK", "") diff --git a/internal/config/config_test.go b/internal/config/config_test.go index e20a715..2917818 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -44,7 +44,7 @@ func TestNew_DefaultValues(t *testing.T) { assert.Equal(t, 8080, cfg.Port) assert.False(t, cfg.Debug) - assert.Equal(t, "./data", cfg.DataDir) + assert.Equal(t, "/var/lib/dnswatcher", cfg.DataDir) assert.Equal(t, time.Hour, cfg.DNSInterval) assert.Equal(t, 12*time.Hour, cfg.TLSInterval) assert.Equal(t, 7, cfg.TLSExpiryWarning) @@ -245,7 +245,7 @@ func TestStatePath(t *testing.T) { dataDir string want string }{ - {"default", "./data", "./data/state.json"}, + {"default", "/var/lib/dnswatcher", "/var/lib/dnswatcher/state.json"}, {"absolute", "/var/lib/dw", "/var/lib/dw/state.json"}, {"nested", "/opt/app/data", "/opt/app/data/state.json"}, {"empty", "", "/state.json"},