Stop requiring current working directory to be the location of AdGuardHome.

Fixes #381.
This commit is contained in:
Eugene Bujak 2018-10-17 20:43:26 +03:00
parent a1bc008190
commit a528ed9f94
2 changed files with 13 additions and 6 deletions

View File

@ -195,8 +195,10 @@ func generateCoreDNSConfigText() (string, error) {
} }
var configBytes bytes.Buffer var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile)
// run the template // run the template
err = t.Execute(&configBytes, config.CoreDNS) err = t.Execute(&configBytes, &temporaryConfig)
if err != nil { if err != nil {
log.Printf("Couldn't generate DNS config: %s", err) log.Printf("Couldn't generate DNS config: %s", err)
return "", err return "", err

View File

@ -3,10 +3,13 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"sync" "os"
"path/filepath"
"sync" // Include all plugins.
// Include all plugins.
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin" _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto" _ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath" _ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind" _ "github.com/coredns/coredns/plugin/bind"
@ -37,9 +40,6 @@ import (
_ "github.com/coredns/coredns/plugin/tls" _ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami" _ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent" _ "github.com/mholt/caddy/onevent"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
) )
// Directives are registered in the order they should be // Directives are registered in the order they should be
@ -109,6 +109,11 @@ func startDNSServer() error {
isCoreDNSRunning = true isCoreDNSRunning = true
isCoreDNSRunningLock.Unlock() isCoreDNSRunningLock.Unlock()
configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
err := writeCoreDNSConfig() err := writeCoreDNSConfig()
if err != nil { if err != nil {
errortext := fmt.Errorf("Unable to write coredns config: %s", err) errortext := fmt.Errorf("Unable to write coredns config: %s", err)