Skip to content

Commit fb7d2a8

Browse files
authored
feat: add option to disable auto config reload (minekube#607)
Add --no-auto-reload flag, GATE_NO_AUTO_RELOAD env var, and noAutoReload config option to disable automatic config file reloading. This addresses issue minekube#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 minekube#602
1 parent 606126c commit fb7d2a8

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

.web/docs/guide/config/reload.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Gate Auto Config Reload - Live Configuration Updates"
3-
description: "Learn about Gate automatic config reloading feature. Update server settings without restarting or disconnecting players."
2+
title: 'Gate Auto Config Reload - Live Configuration Updates'
3+
description: 'Learn about Gate automatic config reloading feature. Update server settings without restarting or disconnecting players.'
44
---
55

66
# Auto Config Reload
@@ -41,6 +41,26 @@ This feature is always enabled by default, given that you have a config file.
4141

4242
## How to disable it
4343

44-
Please note that the auto config reload feature cannot be disabled.
45-
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...)
46-
on our GitHub repository.
44+
You can disable auto config reload in several ways:
45+
46+
### Command line flag
47+
48+
```bash
49+
gate --no-auto-reload
50+
```
51+
52+
### Environment variable
53+
54+
```bash
55+
GATE_NO_AUTO_RELOAD=true gate
56+
```
57+
58+
### Config file
59+
60+
Add to your `config.yml`:
61+
62+
```yaml
63+
noAutoReload: true
64+
```
65+
66+
This is useful in environments where file watching is not available or causes permission issues (e.g., NixOS with sops-nix).

cmd/gate/root.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ func App() *cli.App {
5050
Visit the website https://gate.minekube.com/ for more information.`
5151

5252
var (
53-
debug bool
54-
configFile string
55-
verbosity int
56-
showVersion bool
53+
debug bool
54+
configFile string
55+
verbosity int
56+
showVersion bool
57+
noAutoReload bool
5758
)
5859
app.Flags = []cli.Flag{
5960
&cli.StringFlag{
@@ -83,6 +84,12 @@ Visit the website https://gate.minekube.com/ for more information.`
8384
Usage: "Show version information",
8485
Destination: &showVersion,
8586
},
87+
&cli.BoolFlag{
88+
Name: "no-auto-reload",
89+
Usage: "Disable automatic config file reloading",
90+
Destination: &noAutoReload,
91+
EnvVars: []string{"GATE_NO_AUTO_RELOAD"},
92+
},
8693
}
8794

8895
app.Action = func(c *cli.Context) error {
@@ -134,11 +141,15 @@ Visit the website https://gate.minekube.com/ for more information.`
134141
log.Info("logging verbosity", "verbosity", verbosity)
135142
log.Info("using config file", "config", v.ConfigFileUsed())
136143

144+
// Check if auto reload is disabled (via flag, env var, or config)
145+
disableAutoReload := noAutoReload || cfg.NoAutoReload
146+
137147
// Start Gate
138-
if err = gate.Start(c.Context,
139-
gate.WithConfig(*cfg),
140-
gate.WithAutoConfigReload(v.ConfigFileUsed()),
141-
); err != nil {
148+
startOpts := []gate.StartOption{gate.WithConfig(*cfg)}
149+
if !disableAutoReload && v.ConfigFileUsed() != "" {
150+
startOpts = append(startOpts, gate.WithAutoConfigReload(v.ConfigFileUsed()))
151+
}
152+
if err = gate.Start(c.Context, startOpts...); err != nil {
142153
return cli.Exit(fmt.Errorf("error running Gate: %w", err), 1)
143154
}
144155
return nil

pkg/gate/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type Config struct {
3333
Connect connect.Config `json:"connect,omitempty" yaml:"connect,omitempty"`
3434
// See API struct.
3535
API API `json:"api,omitempty" yaml:"api,omitempty"`
36+
// NoAutoReload disables automatic config file reloading.
37+
// This is useful in environments where file watching causes issues.
38+
NoAutoReload bool `json:"noAutoReload,omitempty" yaml:"noAutoReload,omitempty"`
3639
}
3740

3841
// HealthService is a GRPC health probe service for use with Kubernetes pods.

0 commit comments

Comments
 (0)