cmd: Create pidfile before config load (close #5477)

This commit is contained in:
Matthew Holt 2023-04-03 11:57:16 -06:00
parent f9bd2d3e92
commit 508cf2aa22
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5

View File

@ -208,6 +208,16 @@ func cmdRun(fl Flags) (int, error) {
} }
} }
// create pidfile now, in case loading config takes a while (issue #5477)
if runCmdPidfileFlag != "" {
err := caddy.PIDFile(runCmdPidfileFlag)
if err != nil {
caddy.Log().Error("unable to write PID file",
zap.String("pidfile", runCmdPidfileFlag),
zap.Error(err))
}
}
// run the initial config // run the initial config
err = caddy.Load(config, true) err = caddy.Load(config, true)
if err != nil { if err != nil {
@ -242,16 +252,6 @@ func cmdRun(fl Flags) (int, error) {
go watchConfigFile(configFile, runCmdConfigAdapterFlag) go watchConfigFile(configFile, runCmdConfigAdapterFlag)
} }
// create pidfile
if runCmdPidfileFlag != "" {
err := caddy.PIDFile(runCmdPidfileFlag)
if err != nil {
caddy.Log().Error("unable to write PID file",
zap.String("pidfile", runCmdPidfileFlag),
zap.Error(err))
}
}
// warn if the environment does not provide enough information about the disk // warn if the environment does not provide enough information about the disk
hasXDG := os.Getenv("XDG_DATA_HOME") != "" && hasXDG := os.Getenv("XDG_DATA_HOME") != "" &&
os.Getenv("XDG_CONFIG_HOME") != "" && os.Getenv("XDG_CONFIG_HOME") != "" &&