mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-06 16:02:55 +03:00
cherry-pick: all: opt log levels more
Updates #3929. Squashed commit of the following: commit 0d4aadeff1c4de1440795faf83eb072c46392ff3 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Dec 28 16:34:44 2021 +0300 all: opt log levels more
This commit is contained in:
parent
74dcc91ea7
commit
2eacc46eaa
5 changed files with 40 additions and 25 deletions
internal/home
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/netutil"
|
||||
"github.com/NYTimes/gziphandler"
|
||||
|
@ -175,35 +176,48 @@ func (web *Web) Start() {
|
|||
WriteTimeout: web.conf.WriteTimeout,
|
||||
}
|
||||
go func() {
|
||||
defer log.OnPanic("web: plain")
|
||||
|
||||
errs <- web.httpServer.ListenAndServe()
|
||||
}()
|
||||
|
||||
if web.conf.BetaBindPort != 0 {
|
||||
web.httpServerBeta = &http.Server{
|
||||
ErrorLog: log.StdLog("web: plain", log.DEBUG),
|
||||
Addr: netutil.JoinHostPort(hostStr, web.conf.BetaBindPort),
|
||||
Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta),
|
||||
ReadTimeout: web.conf.ReadTimeout,
|
||||
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
|
||||
WriteTimeout: web.conf.WriteTimeout,
|
||||
}
|
||||
go func() {
|
||||
betaErr := web.httpServerBeta.ListenAndServe()
|
||||
if betaErr != nil {
|
||||
log.Error("starting beta http server: %s", betaErr)
|
||||
}
|
||||
}()
|
||||
}
|
||||
web.startBetaServer(hostStr)
|
||||
|
||||
err := <-errs
|
||||
if err != http.ErrServerClosed {
|
||||
if !errors.Is(err, http.ErrServerClosed) {
|
||||
cleanupAlways()
|
||||
log.Fatal(err)
|
||||
}
|
||||
// We use ErrServerClosed as a sign that we need to rebind on new address, so go back to the start of the loop
|
||||
|
||||
// We use ErrServerClosed as a sign that we need to rebind on a new
|
||||
// address, so go back to the start of the loop.
|
||||
}
|
||||
}
|
||||
|
||||
// startBetaServer starts the beta HTTP server if necessary.
|
||||
func (web *Web) startBetaServer(hostStr string) {
|
||||
if web.conf.BetaBindPort == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
web.httpServerBeta = &http.Server{
|
||||
ErrorLog: log.StdLog("web: plain: beta", log.DEBUG),
|
||||
Addr: netutil.JoinHostPort(hostStr, web.conf.BetaBindPort),
|
||||
Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta),
|
||||
ReadTimeout: web.conf.ReadTimeout,
|
||||
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
|
||||
WriteTimeout: web.conf.WriteTimeout,
|
||||
}
|
||||
go func() {
|
||||
defer log.OnPanic("web: plain: beta")
|
||||
|
||||
betaErr := web.httpServerBeta.ListenAndServe()
|
||||
if betaErr != nil && !errors.Is(betaErr, http.ErrServerClosed) {
|
||||
log.Error("starting beta http server: %s", betaErr)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Close gracefully shuts down the HTTP servers.
|
||||
func (web *Web) Close(ctx context.Context) {
|
||||
log.Info("stopping http server...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue