@marcel91200 / caddy Mirror · read-only / commits / bc447e30
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 21:45 UTC

core: Config LoadInterval -> LoadDelay for clarity

And improve/clarify docs about this feature See #4577

Matthew Holt committed Mar 1, 2022 at 15:04 UTC bc447e307f195b80eeec0f6157e0d8e641af9155
2 files changed +19 -13
admin.go
+12 -6
@@ -101,20 +101,26 @@ type ConfigSettings struct {
101 // are not persisted; only configs that are pushed to Caddy get persisted.
102 Persist *bool `json:"persist,omitempty"`
103
104 - // Loads a configuration to use. This is helpful if your configs are
105 - // managed elsewhere, and you want Caddy to pull its config dynamically
104 + // Loads a new configuration. This is helpful if your configs are
105 + // managed elsewhere and you want Caddy to pull its config dynamically
106 // when it starts. The pulled config completely replaces the current
107 // one, just like any other config load. It is an error if a pulled
108 - // config is configured to pull another config.
108 + // config is configured to pull another config without a load_delay,
109 + // as this creates a tight loop.
110 //
111 // EXPERIMENTAL: Subject to change.
112 LoadRaw json.RawMessage `json:"load,omitempty" caddy:"namespace=caddy.config_loaders inline_key=module"`
113
113 - // The interval to pull config. With a non-zero value, will pull config
114 - // from config loader (eg. a http loader) with given interval.
114 + // The duration after which to load config. If set, config will be pulled
115 + // from the config loader after this duration. A delay is required if a
116 + // dynamically-loaded config is configured to load yet another config. To
117 + // load configs on a regular interval, ensure this value is set the same
118 + // on all loaded configs; it can also be variable if needed, and to stop
119 + // the loop, simply remove dynamic config loading from the next-loaded
120 + // config.
121 //
122 // EXPERIMENTAL: Subject to change.
117 - LoadInterval Duration `json:"load_interval,omitempty"`
123 + LoadDelay Duration `json:"load_delay,omitempty"`
124 }
125
126 // IdentityConfig configures management of this server's identity. An identity
caddy.go
+7 -7
@@ -268,8 +268,8 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
268 newCfg.Admin != nil &&
269 newCfg.Admin.Config != nil &&
270 newCfg.Admin.Config.LoadRaw != nil &&
271 - newCfg.Admin.Config.LoadInterval <= 0 {
272 - return fmt.Errorf("recursive config loading detected: pulled configs cannot pull other configs without positive load_interval")
271 + newCfg.Admin.Config.LoadDelay <= 0 {
272 + return fmt.Errorf("recursive config loading detected: pulled configs cannot pull other configs without positive load_delay")
273 }
274
275 // run the new config and start all its apps
@@ -483,7 +483,7 @@ func finishSettingUp(ctx Context, cfg *Config) error {
483
484 logger := Log().Named("config_loader").With(
485 zap.String("module", val.(Module).CaddyModule().ID.Name()),
486 - zap.Int("pull_interval", int(cfg.Admin.Config.LoadInterval)))
486 + zap.Int("load_delay", int(cfg.Admin.Config.LoadDelay)))
487
488 runLoadedConfig := func(config []byte) {
489 logger.Info("applying dynamically-loaded config")
@@ -495,9 +495,9 @@ func finishSettingUp(ctx Context, cfg *Config) error {
495 }
496 }
497
498 - if cfg.Admin.Config.LoadInterval > 0 {
498 + if cfg.Admin.Config.LoadDelay > 0 {
499 go func() {
500 - timer := time.NewTimer(time.Duration(cfg.Admin.Config.LoadInterval))
500 + timer := time.NewTimer(time.Duration(cfg.Admin.Config.LoadDelay))
501 select {
502 case <-timer.C:
503 loadedConfig, err := val.(ConfigLoader).LoadConfig(ctx)
@@ -510,11 +510,11 @@ func finishSettingUp(ctx Context, cfg *Config) error {
510 if !timer.Stop() {
511 <-timer.C
512 }
513 - Log().Info("stopping config load interval")
513 + Log().Info("stopping dynamic config loading")
514 }
515 }()
516 } else {
517 - // if no LoadInterval is provided, will load config synchronously
517 + // if no LoadDelay is provided, will load config synchronously
518 loadedConfig, err := val.(ConfigLoader).LoadConfig(ctx)
519 if err != nil {
520 return fmt.Errorf("loading dynamic config from %T: %v", val, err)