summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAndreas Schneider <aksdb@gmx.de>2019-10-30 22:12:42 +0100
committerMatt Holt <mholt@users.noreply.github.com>2019-10-30 15:12:42 -0600
commit432b94239d6096e75b413de5a79c6707ab808bc9 (patch)
tree4c7dcef291ff40ea0fed7d6ca24f059a9c379cb8 /cmd
parent4611537f06da0fe77214e4b2c3b4a3330ace0506 (diff)
admin listener as opt-in for initial config (#2834)
* Always cleanup admin endpoint first * Error out if no config has been set (#2833) * Ignore explicitly missing admin config (#2833) * Separate config loading from admin initialization (#2833) * Add admin option to specify admin listener address (#2833) * Use zap for reporting admin endpoint status
Diffstat (limited to 'cmd')
-rw-r--r--cmd/commandfuncs.go16
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