Install writes a fully commented sample env file when no config exists
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -172,10 +172,16 @@ func Install(configPath string, copyBin bool) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A service has no console: without LOG_FILE the output vanishes, so
|
||||
// the installed env file defaults to logging into ProgramData. An
|
||||
// existing LOG_FILE setting is left alone.
|
||||
if err := ensureLogFile(targetCfg, filepath.Join(dataDir, "gpu-turnstile.log")); err != nil {
|
||||
// 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.
|
||||
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 {
|
||||
return fmt.Errorf("write %s: %w", targetCfg, err)
|
||||
}
|
||||
} else if err := ensureLogFile(targetCfg, logPath); err != nil {
|
||||
return err
|
||||
}
|
||||
configPath = targetCfg
|
||||
|
||||
Reference in New Issue
Block a user