*: change initDNSServer method, add getDataDir
This commit is contained in:
parent
9b23acf6da
commit
33ae359cc1
|
@ -239,6 +239,11 @@ func (c *configuration) getConfigFilename() string {
|
||||||
return configFile
|
return configFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getDataDir returns path to the directory where we store databases and filters
|
||||||
|
func (c *configuration) getDataDir() string {
|
||||||
|
return filepath.Join(c.ourWorkingDir, dataDir)
|
||||||
|
}
|
||||||
|
|
||||||
// getLogSettings reads logging settings from the config file.
|
// getLogSettings reads logging settings from the config file.
|
||||||
// we do it in a separate method in order to configure logger before the actual configuration is parsed and applied.
|
// we do it in a separate method in order to configure logger before the actual configuration is parsed and applied.
|
||||||
func getLogSettings() logSettings {
|
func getLogSettings() logSettings {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
|
@ -236,8 +235,7 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||||
config.DNS.BindHost = newSettings.DNS.IP
|
config.DNS.BindHost = newSettings.DNS.IP
|
||||||
config.DNS.Port = newSettings.DNS.Port
|
config.DNS.Port = newSettings.DNS.Port
|
||||||
|
|
||||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
initDNSServer()
|
||||||
initDNSServer(dnsBaseDir)
|
|
||||||
|
|
||||||
err = startDNSServer()
|
err = startDNSServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -263,7 +261,7 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||||
// until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely
|
// until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely
|
||||||
if restartHTTP {
|
if restartHTTP {
|
||||||
go func() {
|
go func() {
|
||||||
config.httpServer.Shutdown(context.TODO())
|
_ = config.httpServer.Shutdown(context.TODO())
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,9 @@ func onConfigModified() {
|
||||||
// initDNSServer creates an instance of the dnsforward.Server
|
// initDNSServer creates an instance of the dnsforward.Server
|
||||||
// Please note that we must do it even if we don't start it
|
// Please note that we must do it even if we don't start it
|
||||||
// so that we had access to the query log and the stats
|
// so that we had access to the query log and the stats
|
||||||
func initDNSServer(baseDir string) {
|
func initDNSServer() {
|
||||||
|
baseDir := config.getDataDir()
|
||||||
|
|
||||||
err := os.MkdirAll(baseDir, 0755)
|
err := os.MkdirAll(baseDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
||||||
|
@ -52,7 +54,7 @@ func initDNSServer(baseDir string) {
|
||||||
config.queryLog = querylog.New(conf)
|
config.queryLog = querylog.New(conf)
|
||||||
config.dnsServer = dnsforward.NewServer(config.stats, config.queryLog)
|
config.dnsServer = dnsforward.NewServer(config.stats, config.queryLog)
|
||||||
|
|
||||||
sessFilename := filepath.Join(config.ourWorkingDir, "data/sessions.db")
|
sessFilename := filepath.Join(baseDir, "sessions.db")
|
||||||
config.auth = InitAuth(sessFilename, config.Users)
|
config.auth = InitAuth(sessFilename, config.Users)
|
||||||
config.Users = nil
|
config.Users = nil
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
func TestResolveRDNS(t *testing.T) {
|
func TestResolveRDNS(t *testing.T) {
|
||||||
config.DNS.BindHost = "1.1.1.1"
|
config.DNS.BindHost = "1.1.1.1"
|
||||||
initDNSServer(".")
|
initDNSServer()
|
||||||
if r := config.dnsctx.rdns.resolve("1.1.1.1"); r != "one.one.one.one" {
|
if r := config.dnsctx.rdns.resolve("1.1.1.1"); r != "one.one.one.one" {
|
||||||
t.Errorf("resolveRDNS(): %s", r)
|
t.Errorf("resolveRDNS(): %s", r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,7 +448,7 @@ func (filter *filter) unload() {
|
||||||
|
|
||||||
// Path to the filter contents
|
// Path to the filter contents
|
||||||
func (filter *filter) Path() string {
|
func (filter *filter) Path() string {
|
||||||
return filepath.Join(config.ourWorkingDir, dataDir, filterDir, strconv.FormatInt(filter.ID, 10)+".txt")
|
return filepath.Join(config.getDataDir(), filterDir, strconv.FormatInt(filter.ID, 10)+".txt")
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastTimeUpdated returns the time when the filter was last time updated
|
// LastTimeUpdated returns the time when the filter was last time updated
|
||||||
|
|
|
@ -142,8 +142,7 @@ func run(args options) {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
initDNSServer()
|
||||||
initDNSServer(dnsBaseDir)
|
|
||||||
|
|
||||||
err = startDNSServer()
|
err = startDNSServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue