From 8dc193b3d5336ed3c293f05a825bc3433ea6b645 Mon Sep 17 00:00:00 2001 From: robinbraemer Date: Mon, 8 Dec 2025 13:36:35 +0100 Subject: [PATCH] feat: add option to disable auto config reload Add --no-auto-reload flag, GATE_NO_AUTO_RELOAD env var, and noAutoReload config option to disable automatic config file reloading. This addresses issue #602 where auto reload fails with permission denied errors in environments like NixOS with sops-nix where file watching is not available or causes issues. Changes: - Added NoAutoReload field to Config struct - Added --no-auto-reload CLI flag - Added GATE_NO_AUTO_RELOAD env var support - Updated documentation Fixes #602 --- .web/docs/guide/config/reload.md | 30 +++++++++++++++++++++++++----- cmd/gate/root.go | 27 +++++++++++++++++++-------- pkg/gate/config/config.go | 3 +++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/.web/docs/guide/config/reload.md b/.web/docs/guide/config/reload.md index c1458eaa4..2147851a2 100644 --- a/.web/docs/guide/config/reload.md +++ b/.web/docs/guide/config/reload.md @@ -1,6 +1,6 @@ --- -title: "Gate Auto Config Reload - Live Configuration Updates" -description: "Learn about Gate automatic config reloading feature. Update server settings without restarting or disconnecting players." +title: 'Gate Auto Config Reload - Live Configuration Updates' +description: 'Learn about Gate automatic config reloading feature. Update server settings without restarting or disconnecting players.' --- # Auto Config Reload @@ -41,6 +41,26 @@ This feature is always enabled by default, given that you have a config file. ## How to disable it -Please note that the auto config reload feature cannot be disabled. -If you feel a compelling need to do so, please don't hesitate to [open an issue](https://github.com/minekube/gate/issues/new?title=Disable%20auto%20config%20reload&body=I%20want%20to%20disable%20auto%20config%20reload%20because%20...) -on our GitHub repository. +You can disable auto config reload in several ways: + +### Command line flag + +```bash +gate --no-auto-reload +``` + +### Environment variable + +```bash +GATE_NO_AUTO_RELOAD=true gate +``` + +### Config file + +Add to your `config.yml`: + +```yaml +noAutoReload: true +``` + +This is useful in environments where file watching is not available or causes permission issues (e.g., NixOS with sops-nix). diff --git a/cmd/gate/root.go b/cmd/gate/root.go index 567c9b505..3c337156c 100644 --- a/cmd/gate/root.go +++ b/cmd/gate/root.go @@ -50,10 +50,11 @@ func App() *cli.App { Visit the website https://gate.minekube.com/ for more information.` var ( - debug bool - configFile string - verbosity int - showVersion bool + debug bool + configFile string + verbosity int + showVersion bool + noAutoReload bool ) app.Flags = []cli.Flag{ &cli.StringFlag{ @@ -83,6 +84,12 @@ Visit the website https://gate.minekube.com/ for more information.` Usage: "Show version information", Destination: &showVersion, }, + &cli.BoolFlag{ + Name: "no-auto-reload", + Usage: "Disable automatic config file reloading", + Destination: &noAutoReload, + EnvVars: []string{"GATE_NO_AUTO_RELOAD"}, + }, } app.Action = func(c *cli.Context) error { @@ -134,11 +141,15 @@ Visit the website https://gate.minekube.com/ for more information.` log.Info("logging verbosity", "verbosity", verbosity) log.Info("using config file", "config", v.ConfigFileUsed()) + // Check if auto reload is disabled (via flag, env var, or config) + disableAutoReload := noAutoReload || cfg.NoAutoReload + // Start Gate - if err = gate.Start(c.Context, - gate.WithConfig(*cfg), - gate.WithAutoConfigReload(v.ConfigFileUsed()), - ); err != nil { + startOpts := []gate.StartOption{gate.WithConfig(*cfg)} + if !disableAutoReload && v.ConfigFileUsed() != "" { + startOpts = append(startOpts, gate.WithAutoConfigReload(v.ConfigFileUsed())) + } + if err = gate.Start(c.Context, startOpts...); err != nil { return cli.Exit(fmt.Errorf("error running Gate: %w", err), 1) } return nil diff --git a/pkg/gate/config/config.go b/pkg/gate/config/config.go index 412319d5e..81bfe8572 100644 --- a/pkg/gate/config/config.go +++ b/pkg/gate/config/config.go @@ -33,6 +33,9 @@ type Config struct { Connect connect.Config `json:"connect,omitempty" yaml:"connect,omitempty"` // See API struct. API API `json:"api,omitempty" yaml:"api,omitempty"` + // NoAutoReload disables automatic config file reloading. + // This is useful in environments where file watching causes issues. + NoAutoReload bool `json:"noAutoReload,omitempty" yaml:"noAutoReload,omitempty"` } // HealthService is a GRPC health probe service for use with Kubernetes pods.