mirror of
https://github.com/caddyserver/caddy.git
synced 2026-09-01 00:48:03 +00:00
cmd: Add pidfile support (closes #3235)
This commit is contained in:
parent
cee5589b98
commit
4df56c77e3
4 changed files with 38 additions and 9 deletions
|
|
@ -41,6 +41,7 @@ import (
|
|||
func cmdStart(fl Flags) (int, error) {
|
||||
startCmdConfigFlag := fl.String("config")
|
||||
startCmdConfigAdapterFlag := fl.String("adapter")
|
||||
startCmdPidfileFlag := fl.String("pidfile")
|
||||
startCmdWatchFlag := fl.Bool("watch")
|
||||
|
||||
// open a listener to which the child process will connect when
|
||||
|
|
@ -71,6 +72,9 @@ func cmdStart(fl Flags) (int, error) {
|
|||
if startCmdWatchFlag {
|
||||
cmd.Args = append(cmd.Args, "--watch")
|
||||
}
|
||||
if startCmdPidfileFlag != "" {
|
||||
cmd.Args = append(cmd.Args, "--pidfile", startCmdPidfileFlag)
|
||||
}
|
||||
stdinpipe, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup,
|
||||
|
|
@ -149,6 +153,7 @@ func cmdRun(fl Flags) (int, error) {
|
|||
runCmdResumeFlag := fl.Bool("resume")
|
||||
runCmdPrintEnvFlag := fl.Bool("environ")
|
||||
runCmdWatchFlag := fl.Bool("watch")
|
||||
runCmdPidfileFlag := fl.String("pidfile")
|
||||
runCmdPingbackFlag := fl.String("pingback")
|
||||
|
||||
// if we are supposed to print the environment, do that first
|
||||
|
|
@ -225,6 +230,16 @@ 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") != "" &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue