diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/commandfuncs.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index 7c08c2e..d73644c 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -161,12 +161,24 @@ func cmdRun(fl Flags) (int, error) { certmagic.UserAgent = "Caddy/" + cleanModVersion // start the admin endpoint along with any initial config + // a configuration without admin config is considered fine + // but does not enable the admin endpoint at all err = caddy.StartAdmin(config) - if err != nil { + if err == nil { + defer caddy.StopAdmin() + } else if err != caddy.ErrAdminInterfaceNotConfigured { return caddy.ExitCodeFailedStartup, fmt.Errorf("starting caddy administration endpoint: %v", err) } - defer caddy.StopAdmin() + + // if a config has been supplied, load it as initial config + if len(config) > 0 { + err := caddy.Load(bytes.NewReader(config)) + if err != nil { + return caddy.ExitCodeFailedStartup, fmt.Errorf("loading initial config: %v", err) + } + caddy.Log().Named("admin").Info("Caddy 2 serving initial configuration") + } // if we are to report to another process the successful start // of the server, do so now by echoing back contents of stdin |