Pull request 2156: 6717-conf-path-logs

Updates .

Squashed commit of the following:

commit 05a7e18923e987ea9bd6294fe675a22cf86f6dce
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Feb 21 16:44:00 2024 +0300

    home: imp docs, logs
This commit is contained in:
Ainar Garipov 2024-02-21 17:01:15 +03:00
parent 4605e7c90e
commit 9276afd79d
4 changed files with 71 additions and 41 deletions
internal/home

View file

@ -40,7 +40,6 @@ import (
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/osutil"
"github.com/AdguardTeam/golibs/stringutil"
)
// Global context
@ -68,11 +67,14 @@ type homeContext struct {
// Runtime properties
// --
configFilename string // Config filename (can be overridden via the command line arguments)
workDir string // Location of our directory, used to protect against CWD being somewhere else
pidFileName string // PID file name. Empty if no PID file was created.
controlLock sync.Mutex
tlsRoots *x509.CertPool // list of root CAs for TLSv1.2
// confFilePath is the configuration file path as set by default or from the
// command-line options.
confFilePath string
workDir string // Location of our directory, used to protect against CWD being somewhere else
pidFileName string // PID file name. Empty if no PID file was created.
controlLock sync.Mutex
tlsRoots *x509.CertPool // list of root CAs for TLSv1.2
// tlsCipherIDs are the ID of the cipher suites that AdGuard Home must use.
tlsCipherIDs []uint16
@ -575,6 +577,9 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
Path: path.Join("adguardhome", version.Channel(), "version.json"),
}
confPath := configFilePath()
log.Debug("using config path %q for updater", confPath)
upd := updater.NewUpdater(&updater.Config{
Client: config.Filtering.HTTPClient,
Version: version.Version(),
@ -584,7 +589,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
GOARM: version.GOARM(),
GOMIPS: version.GOMIPS(),
WorkDir: Context.workDir,
ConfName: config.getConfigFilename(),
ConfName: confPath,
ExecPath: execPath,
VersionCheckURL: u.String(),
})
@ -748,7 +753,16 @@ func writePIDFile(fn string) bool {
// initConfigFilename sets up context config file path. This file path can be
// overridden by command-line arguments, or is set to default.
func initConfigFilename(opts options) {
Context.configFilename = stringutil.Coalesce(opts.confFilename, "AdGuardHome.yaml")
confPath := opts.confFilename
if confPath == "" {
Context.confFilePath = "AdGuardHome.yaml"
return
}
log.Debug("config path overridden to %q from cmdline", confPath)
Context.confFilePath = confPath
}
// initWorkingDir initializes the workDir. If no command-line arguments are
@ -906,16 +920,23 @@ func printHTTPAddresses(proto string) {
}
}
// -------------------
// first run / install
// -------------------
func detectFirstRun() bool {
configfile := Context.configFilename
if !filepath.IsAbs(configfile) {
configfile = filepath.Join(Context.workDir, Context.configFilename)
// detectFirstRun returns true if this is the first run of AdGuard Home.
func detectFirstRun() (ok bool) {
confPath := Context.confFilePath
if !filepath.IsAbs(confPath) {
confPath = filepath.Join(Context.workDir, Context.confFilePath)
}
_, err := os.Stat(configfile)
return errors.Is(err, os.ErrNotExist)
_, err := os.Stat(confPath)
if err == nil {
return false
} else if errors.Is(err, os.ErrNotExist) {
return true
}
log.Error("detecting first run: %s; considering first run", err)
return true
}
// jsonError is a generic JSON error response.