Sync the env file at startup, not just at install: updates append new settings
This commit is contained in:
@@ -172,6 +172,7 @@ func main() {
|
||||
}
|
||||
log, logOut, logCloser := newLogger(cfg)
|
||||
defer logCloser.Close()
|
||||
syncEnvFile(resolveConfigPath(configPath), cfg.LogFile, log)
|
||||
|
||||
if service.IsService() {
|
||||
if err := service.Run(func(ctx context.Context) error { return run(ctx, cfg, log, logOut, true) }); err != nil {
|
||||
@@ -188,6 +189,27 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// syncEnvFile upgrades an installer-written config file after an update:
|
||||
// settings added since its CFG_VER are appended (commented out) and CFG_VER
|
||||
// is bumped. Files not written by the installer (no CFG_VER), up-to-date
|
||||
// files and dev builds are left untouched; a write failure is logged, not
|
||||
// fatal.
|
||||
func syncEnvFile(path, logFile string, log *slog.Logger) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return // no config file; nothing to upgrade
|
||||
}
|
||||
synced, changed := config.SyncSample(string(data), version, logFile)
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(synced), 0o644); err != nil {
|
||||
log.Warn("could not append new settings to the config file", "path", path, "err", err)
|
||||
return
|
||||
}
|
||||
log.Warn("config file updated: new settings appended", "path", path, "version", version)
|
||||
}
|
||||
|
||||
// defaultConfigPath returns gpu-turnstile.env next to the executable.
|
||||
func defaultConfigPath() string {
|
||||
exe, err := os.Executable()
|
||||
|
||||
Reference in New Issue
Block a user