From 68be4a91610a17c95716bd06c3191282dd9ce47c Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 10 Aug 2016 23:46:04 -0600 Subject: [PATCH] Don't prompt for email when user is not there to provide one Also don't bother showing stdout output in same situation --- caddy.go | 23 +++++++++++++++++++++++ caddyhttp/httpserver/https.go | 9 ++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/caddy.go b/caddy.go index 1b1caf54..ff578d12 100644 --- a/caddy.go +++ b/caddy.go @@ -50,6 +50,14 @@ var ( // was started as part of an upgrade, where a parent // Caddy process started this one. isUpgrade bool + + // started will be set to true when the first + // instance is started; it never gets set to + // false after that. + started bool + + // mu protects the variables 'isUpgrade' and 'started'. + mu sync.Mutex ) // Instance contains the state of servers created as a result of @@ -497,6 +505,10 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r } } + mu.Lock() + started = true + mu.Unlock() + return nil } @@ -737,9 +749,20 @@ func Upgrade() error { // where a parent caddy process spawned this one to ugprade // the binary. func IsUpgrade() bool { + mu.Lock() + defer mu.Unlock() return isUpgrade } +// Started returns true if at least one instance has been +// started by this package. It never gets reset to false +// once it is set to true. +func Started() bool { + mu.Lock() + defer mu.Unlock() + return started +} + // CaddyfileInput represents a Caddyfile as input // and is simply a convenient way to implement // the Input interface. diff --git a/caddyhttp/httpserver/https.go b/caddyhttp/httpserver/https.go index 3a6ebb70..825f028d 100644 --- a/caddyhttp/httpserver/https.go +++ b/caddyhttp/httpserver/https.go @@ -10,7 +10,9 @@ import ( ) func activateHTTPS(cctx caddy.Context) error { - if !caddy.Quiet { + operatorPresent := !caddy.Started() + + if !caddy.Quiet && operatorPresent { fmt.Print("Activating privacy features...") } @@ -21,7 +23,7 @@ func activateHTTPS(cctx caddy.Context) error { // place certificates and keys on disk for _, c := range ctx.siteConfigs { - err := c.TLS.ObtainCert(true) + err := c.TLS.ObtainCert(operatorPresent) if err != nil { return err } @@ -44,9 +46,10 @@ func activateHTTPS(cctx caddy.Context) error { return err } - if !caddy.Quiet { + if !caddy.Quiet && operatorPresent { fmt.Println(" done.") } + return nil }