mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-28 18:08:51 +03:00
f5602d9c46
Merge in DNS/adguard-home from hup-reload to master Squashed commit of the following: commit 5cd4ab85bdc7544a4eded2a61f5a5571175daa44 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Oct 7 19:58:17 2022 +0300 next: imp signal hdlr commit 8fd18e749fec46982d26fc408e661bd802586c37 Merge: a8780455f1dd3334
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Oct 7 19:46:48 2022 +0300 Merge branch 'master' into hup-reload commit a87804550e15d7fe3d9ded2e5a736c395f96febd Merge: 349dbe54960a7a75
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Oct 7 15:49:23 2022 +0300 Merge branch 'master' into hup-reload commit 349dbe54fe27eeaf56776c73c3cc5649018d4c60 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Oct 7 15:43:52 2022 +0300 next: imp docs, names commit 7287a86d283489127453009267911003cea5227e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Oct 7 13:39:44 2022 +0300 WIP all: impl dynamic reconfiguration
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
// Package cmd is the AdGuard Home entry point. It contains the on-disk
|
|
// configuration file utilities, signal processing logic, and so on.
|
|
//
|
|
// TODO(a.garipov): Move to the upper-level internal/.
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"io/fs"
|
|
"math/rand"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/next/configmgr"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
|
"github.com/AdguardTeam/golibs/log"
|
|
)
|
|
|
|
// Main is the entry point of application.
|
|
func Main(clientBuildFS fs.FS) {
|
|
// Initial Configuration
|
|
|
|
start := time.Now()
|
|
rand.Seed(start.UnixNano())
|
|
|
|
// TODO(a.garipov): Set up logging.
|
|
|
|
log.Info("starting adguard home, version %s, pid %d", version.Version(), os.Getpid())
|
|
|
|
// Web Service
|
|
|
|
// TODO(a.garipov): Use in the Web service.
|
|
_ = clientBuildFS
|
|
|
|
// TODO(a.garipov): Set up configuration file name.
|
|
const confFile = "AdGuardHome.1.yaml"
|
|
|
|
confMgr, err := configmgr.New(confFile, start)
|
|
fatalOnError(err)
|
|
|
|
web := confMgr.Web()
|
|
err = web.Start()
|
|
fatalOnError(err)
|
|
|
|
dns := confMgr.DNS()
|
|
err = dns.Start()
|
|
fatalOnError(err)
|
|
|
|
sigHdlr := newSignalHandler(
|
|
confFile,
|
|
start,
|
|
web,
|
|
dns,
|
|
)
|
|
|
|
go sigHdlr.handle()
|
|
|
|
select {}
|
|
}
|
|
|
|
// defaultTimeout is the timeout used for some operations where another timeout
|
|
// hasn't been defined yet.
|
|
const defaultTimeout = 15 * time.Second
|
|
|
|
// ctxWithDefaultTimeout is a helper function that returns a context with
|
|
// timeout set to defaultTimeout.
|
|
func ctxWithDefaultTimeout() (ctx context.Context, cancel context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), defaultTimeout)
|
|
}
|
|
|
|
// fatalOnError is a helper that exits the program with an error code if err is
|
|
// not nil. It must only be used within Main.
|
|
func fatalOnError(err error) {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|