Install writes a fully commented sample env file when no config exists

This commit is contained in:
mram
2026-09-21 08:48:51 +02:00
parent dd3187f951
commit cf48796183
6 changed files with 145 additions and 18 deletions
+13 -4
View File
@@ -15,6 +15,8 @@ import (
"os/signal"
"path/filepath"
"syscall"
"gpu-turnstile/internal/config"
)
// Name matches the Windows service name; the systemd unit is Name + ".service".
@@ -170,10 +172,17 @@ func Install(configPath string, copyBin bool) error {
}
}
exe = installedExe
if _, err := os.Stat(etcConfig); os.IsNotExist(err) && configPath != "" {
// Missing config is not fatal: the service fails fast with a
// clear "no consumer URL" error until the user writes one.
copyFile(configPath, etcConfig, 0o644) //nolint:errcheck // best effort
if _, err := os.Stat(etcConfig); os.IsNotExist(err) {
if configPath != "" {
copyFile(configPath, etcConfig, 0o644) //nolint:errcheck // best effort
} else {
// No config at all: install a fully commented sample
// covering every setting. LOG_FILE stays commented —
// stderr goes to the journal on Linux.
if err := os.WriteFile(etcConfig, []byte(config.SampleEnv("")), 0o644); err != nil {
return fmt.Errorf("write %s: %w", etcConfig, err)
}
}
}
} else if configPath != "" {
if abs, absErr := filepath.Abs(configPath); absErr == nil {