Skip to content

Commit

Permalink
cmd: Create pidfile before config load (close #5477)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Apr 3, 2023
1 parent f9bd2d3 commit 508cf2a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
err = caddy.Load(config, true)
if err != nil {
Expand Down Expand Up @@ -242,16 +252,6 @@ func cmdRun(fl Flags) (int, error) {
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
hasXDG := os.Getenv("XDG_DATA_HOME") != "" &&
os.Getenv("XDG_CONFIG_HOME") != "" &&
Expand Down

0 comments on commit 508cf2a

Please sign in to comment.