refactor: move vpn-dns config directory from /etc/coredns to /tmp/nexavpn-vpn-dns
Add configDir, corefilePath, and overridesPath constants pointing to /tmp/nexavpn-vpn-dns directory. Update all file path references in writeCorefile and refreshOverrides to use new constants instead of hardcoded /etc/coredns paths.
This commit is contained in:
@@ -14,6 +14,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
configDir = "/tmp/nexavpn-vpn-dns"
|
||||
corefilePath = configDir + "/Corefile"
|
||||
overridesPath = configDir + "/service-overrides.hosts"
|
||||
)
|
||||
|
||||
type dnsResponse struct {
|
||||
Records []dnsRecord `json:"records"`
|
||||
}
|
||||
@@ -26,7 +32,7 @@ type dnsRecord struct {
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := os.MkdirAll("/etc/coredns", 0o755); err != nil {
|
||||
if err := os.MkdirAll(configDir, 0o755); err != nil {
|
||||
log.Fatalf("unable to create coredns config dir: %v", err)
|
||||
}
|
||||
|
||||
@@ -47,7 +53,7 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
cmd := exec.Command("/coredns", "-conf", "/etc/coredns/Corefile")
|
||||
cmd := exec.Command("/coredns", "-conf", corefilePath)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -65,7 +71,7 @@ func writeCorefile() error {
|
||||
|
||||
corefile := fmt.Sprintf(`%s {
|
||||
errors
|
||||
hosts /etc/coredns/service-overrides.hosts {
|
||||
hosts ` + overridesPath + ` {
|
||||
ttl 30
|
||||
reload 15s
|
||||
fallthrough
|
||||
@@ -75,7 +81,7 @@ func writeCorefile() error {
|
||||
}
|
||||
`, envOrDefault("NEXAVPN_VPN_DNS_ADDR", ":53"), strings.Join(upstreams, " "))
|
||||
|
||||
return os.WriteFile("/etc/coredns/Corefile", []byte(corefile), 0o644)
|
||||
return os.WriteFile(corefilePath, []byte(corefile), 0o644)
|
||||
}
|
||||
|
||||
func refreshOverrides(ctx context.Context) error {
|
||||
@@ -116,7 +122,7 @@ func refreshOverrides(ctx context.Context) error {
|
||||
content += "\n"
|
||||
}
|
||||
|
||||
return os.WriteFile(filepath.Clean("/etc/coredns/service-overrides.hosts"), []byte(content), 0o644)
|
||||
return os.WriteFile(filepath.Clean(overridesPath), []byte(content), 0o644)
|
||||
}
|
||||
|
||||
func parseList(raw string) []string {
|
||||
|
||||
Reference in New Issue
Block a user