mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 11:35:35 +00:00
router: reload systemd-resolved after changing /etc/resolv.conf (#619)
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
This commit is contained in:
parent
cbf71d5eba
commit
154d1cde05
@ -13,6 +13,8 @@
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
@ -79,6 +81,25 @@ func dnsReadConfig() (DNSConfig, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isResolvedRunning reports whether systemd-resolved is running on the system,
|
||||||
|
// even if it is not managing the system DNS settings.
|
||||||
|
func isResolvedRunning() bool {
|
||||||
|
if runtime.GOOS != "linux" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// systemd-resolved is never installed without systemd.
|
||||||
|
_, err := exec.LookPath("systemctl")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// is-active exits with code 3 if the service is not active.
|
||||||
|
err = exec.Command("systemctl", "is-active", "systemd-resolved.service").Run()
|
||||||
|
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
// dnsDirectUp replaces /etc/resolv.conf with a file generated
|
// dnsDirectUp replaces /etc/resolv.conf with a file generated
|
||||||
// from the given configuration, creating a backup of its old state.
|
// from the given configuration, creating a backup of its old state.
|
||||||
//
|
//
|
||||||
@ -124,6 +145,10 @@ func dnsDirectUp(config DNSConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isResolvedRunning() {
|
||||||
|
exec.Command("systemctl", "restart", "systemd-resolved.service").Run() // Best-effort.
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,5 +172,10 @@ func dnsDirectDown() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
os.Remove(tsConf)
|
os.Remove(tsConf)
|
||||||
|
|
||||||
|
if isResolvedRunning() {
|
||||||
|
exec.Command("systemctl", "restart", "systemd-resolved.service").Run() // Best-effort.
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user