Configuration Hot Reloading#
GLAuth supports automatic reloading of its TOML configuration file at runtime, without requiring a service restart. This is controlled by the watchconfig boolean in the top-level config .
Enabling#
Set watchconfig = true in your TOML config file :
# Enable hot-reload of configuration on changes
watchconfig = true
What Gets Reloaded — and What Doesn't#
Important: Hot reloading does not apply to the
[ldap],[ldaps],[backend], or[api]sections . Changes to those sections require a full service restart. Sections that are live-reloadable include users, groups, behaviors, and other top-level settings.
How It Works#
startConfigWatcher() is called during service startup . It:
- Exits early if
WatchConfigis false, or if the config location is an S3 URL (hot reload is only supported for local files) . - Creates an
fsnotify.Watcherto watch the config file path . - Runs a goroutine that listens for
fsnotifyevents on the file. It handles three event types :Write— file was directly modifiedRemove— file was deleted (handles editors like vim that use rename/remove atomically)Create— file was recreated (when watching a directory)
- Coalesces changes with a 1-second ticker to avoid reloading on every partial write .
- On a detected change, calls
toml.NewConfig()to re-parse the file, then usescopier.Copyto overwrite the in-processactiveConfigpointer in place . If parsing fails, the old config is retained . - Re-watches the file after a
Removeevent (vim-style atomic saves), once the file reappears .
Key Files#
| File | Purpose |
|---|---|
v2/glauth.go | startConfigWatcher() — fsnotify watcher loop |
v2/pkg/config/config.go | Config.WatchConfig field definition |
v2/internal/toml/config.go | NewConfig() — TOML parsing invoked on each reload |
v2/sample-simple.cfg | Reference config showing watchconfig usage |
Caveats#
- S3 configs are not supported. The watcher skips if the config path starts with
s3://. - Structural sections are not hot-reloaded. Server listen addresses, TLS certificates, and backend/API settings take effect only on restart .
- Parse errors are non-fatal. A bad config file during a reload is logged and the old config is kept active .
activeConfigis mutated in place viacopier.Copy, so any running handler holding a reference to the struct will see the updated values immediately .