cmd/ctrld: always process "--cd" in start mode

So if there's any error in fetching configuration, it will be reported
to user and service won't start.
This commit is contained in:
Cuong Manh Le
2023-01-21 01:13:54 +07:00
committed by Cuong Manh Le
parent 14ddb1faa0
commit d830706692
+3 -4
View File
@@ -187,7 +187,6 @@ func initCLI() {
osArgs = os.Args[3:] osArgs = os.Args[3:]
} }
sc.Arguments = append([]string{"run"}, osArgs...) sc.Arguments = append([]string{"run"}, osArgs...)
isWindows := runtime.GOOS == "windows"
if dir, err := os.UserHomeDir(); err == nil { if dir, err := os.UserHomeDir(); err == nil {
// WorkingDirectory is not supported on Windows. // WorkingDirectory is not supported on Windows.
sc.WorkingDirectory = dir sc.WorkingDirectory = dir
@@ -196,15 +195,15 @@ func initCLI() {
writeDefaultConfig := !noConfigStart && configBase64 == "" writeDefaultConfig := !noConfigStart && configBase64 == ""
if configPath == "" && writeDefaultConfig { if configPath == "" && writeDefaultConfig {
defaultConfigFile = filepath.Join(dir, defaultConfigFile) defaultConfigFile = filepath.Join(dir, defaultConfigFile)
readConfigFile(writeDefaultConfig && (cdUID == "" || !isWindows)) readConfigFile(writeDefaultConfig && cdUID == "")
} }
sc.Arguments = append(sc.Arguments, "--homedir="+dir) sc.Arguments = append(sc.Arguments, "--homedir="+dir)
} }
processCDFlags()
// On Windows, the service will be run as SYSTEM, so if ctrld start as Admin, // On Windows, the service will be run as SYSTEM, so if ctrld start as Admin,
// the user home dir is different, so pass specific arguments that relevant here. // the user home dir is different, so pass specific arguments that relevant here.
if isWindows { if runtime.GOOS == "windows" {
processCDFlags()
if configPath == "" { if configPath == "" {
sc.Arguments = append(sc.Arguments, "--config="+defaultConfigFile) sc.Arguments = append(sc.Arguments, "--config="+defaultConfigFile)
} }