Sample env carries a version marker; install appends settings missing since the writing version

This commit is contained in:
mram
2026-09-21 08:54:47 +02:00
parent cf48796183
commit e46e92bee8
7 changed files with 239 additions and 46 deletions
+18 -7
View File
@@ -116,7 +116,7 @@ func (h *handler) Execute(_ []string, requests <-chan svc.ChangeRequest, status
// the installed binary is refreshed only when the content differs, the
// registration is updated only where it drifted, and the service is
// started again only if it was running before.
func Install(configPath string, copyBin bool) error {
func Install(configPath string, copyBin bool, version string) error {
exe, err := os.Executable()
if err != nil {
return err
@@ -174,15 +174,26 @@ func Install(configPath string, copyBin bool) error {
}
// A service has no console: without LOG_FILE the output vanishes.
// With no config at all, install a fully commented sample covering
// every setting (only LOG_FILE active); an existing config just gets
// a LOG_FILE line appended if it has none.
// every setting (only LOG_FILE active). An existing installer-written
// config from an older version gets any new settings appended; any
// other existing config just gets a LOG_FILE line if it has none.
logPath := filepath.Join(dataDir, "gpu-turnstile.log")
if _, statErr := os.Stat(targetCfg); os.IsNotExist(statErr) {
if err := os.WriteFile(targetCfg, []byte(config.SampleEnv(logPath)), 0o644); err != nil {
data, readErr := os.ReadFile(targetCfg)
switch {
case os.IsNotExist(readErr):
if err := os.WriteFile(targetCfg, []byte(config.SampleEnv(version, logPath)), 0o644); err != nil {
return fmt.Errorf("write %s: %w", targetCfg, err)
}
} else if err := ensureLogFile(targetCfg, logPath); err != nil {
return err
case readErr != nil:
return fmt.Errorf("read %s: %w", targetCfg, readErr)
default:
if synced, changed := config.SyncSample(string(data), version, logPath); changed {
if err := os.WriteFile(targetCfg, []byte(synced), 0o644); err != nil {
return fmt.Errorf("write %s: %w", targetCfg, err)
}
} else if err := ensureLogFile(targetCfg, logPath); err != nil {
return err
}
}
configPath = targetCfg
}