mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
admin: Don't stop old server if new one fails (#4964)
Fixes #4954 Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
5fb5b81439
commit
4c282e86da
1 changed files with 4 additions and 2 deletions
6
admin.go
6
admin.go
|
@ -340,17 +340,19 @@ func (admin AdminConfig) allowedOrigins(addr NetworkAddress) []*url.URL {
|
||||||
// that there is always an admin server (unless it is explicitly
|
// that there is always an admin server (unless it is explicitly
|
||||||
// configured to be disabled).
|
// configured to be disabled).
|
||||||
func replaceLocalAdminServer(cfg *Config) error {
|
func replaceLocalAdminServer(cfg *Config) error {
|
||||||
// always be sure to close down the old admin endpoint
|
// always* be sure to close down the old admin endpoint
|
||||||
// as gracefully as possible, even if the new one is
|
// as gracefully as possible, even if the new one is
|
||||||
// disabled -- careful to use reference to the current
|
// disabled -- careful to use reference to the current
|
||||||
// (old) admin endpoint since it will be different
|
// (old) admin endpoint since it will be different
|
||||||
// when the function returns
|
// when the function returns
|
||||||
|
// (* except if the new one fails to start)
|
||||||
oldAdminServer := localAdminServer
|
oldAdminServer := localAdminServer
|
||||||
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
// do the shutdown asynchronously so that any
|
// do the shutdown asynchronously so that any
|
||||||
// current API request gets a response; this
|
// current API request gets a response; this
|
||||||
// goroutine may last a few seconds
|
// goroutine may last a few seconds
|
||||||
if oldAdminServer != nil {
|
if oldAdminServer != nil && err == nil {
|
||||||
go func(oldAdminServer *http.Server) {
|
go func(oldAdminServer *http.Server) {
|
||||||
err := stopAdminServer(oldAdminServer)
|
err := stopAdminServer(oldAdminServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue