mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
cmd/cli: always reset DNS before installing ctrld
So ctrld could always gather the correct nameservers for OS resolver.
This commit is contained in:
committed by
Cuong Manh Le
parent
b9f2259ae4
commit
34801382f5
+17
-9
@@ -184,9 +184,10 @@ func initCLI() {
|
|||||||
|
|
||||||
status, err := s.Status()
|
status, err := s.Status()
|
||||||
isCtrldInstalled := !errors.Is(err, service.ErrNotInstalled)
|
isCtrldInstalled := !errors.Is(err, service.ErrNotInstalled)
|
||||||
|
isCtrldRunning := status == service.StatusRunning
|
||||||
|
|
||||||
// If pin code was set, do not allow running start command.
|
// If pin code was set, do not allow running start command.
|
||||||
if status == service.StatusRunning {
|
if isCtrldRunning {
|
||||||
if err := checkDeactivationPin(s, nil); isCheckDeactivationPinErr(err) {
|
if err := checkDeactivationPin(s, nil); isCheckDeactivationPinErr(err) {
|
||||||
os.Exit(deactivationPinInvalidExitCode)
|
os.Exit(deactivationPinInvalidExitCode)
|
||||||
}
|
}
|
||||||
@@ -308,18 +309,25 @@ func initCLI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks := []task{
|
tasks := []task{
|
||||||
|
{func() error {
|
||||||
|
// Always reset DNS first, ensuring DNS setting is in a good state.
|
||||||
|
// resetDNS must use the "iface" value of current running ctrld
|
||||||
|
// process to reset what setDNS has done properly.
|
||||||
|
oldIface := iface
|
||||||
|
iface = "auto"
|
||||||
|
if isCtrldRunning {
|
||||||
|
iface = runningIface(s)
|
||||||
|
}
|
||||||
|
if isCtrldInstalled {
|
||||||
|
resetDnsNoLog(p)
|
||||||
|
}
|
||||||
|
iface = oldIface
|
||||||
|
return nil
|
||||||
|
}, false},
|
||||||
{s.Stop, false},
|
{s.Stop, false},
|
||||||
{func() error { return doGenerateNextDNSConfig(nextdns) }, true},
|
{func() error { return doGenerateNextDNSConfig(nextdns) }, true},
|
||||||
{func() error { return ensureUninstall(s) }, false},
|
{func() error { return ensureUninstall(s) }, false},
|
||||||
{func() error {
|
{func() error {
|
||||||
// If ctrld is installed, we should not save current DNS settings, because:
|
|
||||||
//
|
|
||||||
// - The DNS settings was being set by ctrld already.
|
|
||||||
// - We could not determine the state of DNS settings before installing ctrld.
|
|
||||||
if isCtrldInstalled {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save current DNS so we can restore later.
|
// Save current DNS so we can restore later.
|
||||||
withEachPhysicalInterfaces("", "save DNS settings", func(i *net.Interface) error {
|
withEachPhysicalInterfaces("", "save DNS settings", func(i *net.Interface) error {
|
||||||
return saveCurrentStaticDNS(i)
|
return saveCurrentStaticDNS(i)
|
||||||
|
|||||||
+11
-9
@@ -452,11 +452,12 @@ func (p *prog) setDNS() {
|
|||||||
if iface == "" {
|
if iface == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
runningIface := iface
|
||||||
// allIfaces tracks whether we should set DNS for all physical interfaces.
|
// allIfaces tracks whether we should set DNS for all physical interfaces.
|
||||||
allIfaces := false
|
allIfaces := false
|
||||||
if iface == "auto" {
|
if runningIface == "auto" {
|
||||||
iface = defaultIfaceName()
|
runningIface = defaultIfaceName()
|
||||||
// If iface is "auto", it means user does not specify "--iface" flag.
|
// If runningIface is "auto", it means user does not specify "--iface" flag.
|
||||||
// In this case, ctrld has to set DNS for all physical interfaces, so
|
// In this case, ctrld has to set DNS for all physical interfaces, so
|
||||||
// thing will still work when user switch from one to the other.
|
// thing will still work when user switch from one to the other.
|
||||||
allIfaces = requiredMultiNICsConfig()
|
allIfaces = requiredMultiNICsConfig()
|
||||||
@@ -465,8 +466,8 @@ func (p *prog) setDNS() {
|
|||||||
if lc == nil {
|
if lc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger := mainLog.Load().With().Str("iface", iface).Logger()
|
logger := mainLog.Load().With().Str("iface", runningIface).Logger()
|
||||||
netIface, err := netInterface(iface)
|
netIface, err := netInterface(runningIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Err(err).Msg("could not get interface")
|
logger.Error().Err(err).Msg("could not get interface")
|
||||||
return
|
return
|
||||||
@@ -520,14 +521,15 @@ func (p *prog) resetDNS() {
|
|||||||
if iface == "" {
|
if iface == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
runningIface := iface
|
||||||
allIfaces := false
|
allIfaces := false
|
||||||
if iface == "auto" {
|
if runningIface == "auto" {
|
||||||
iface = defaultIfaceName()
|
runningIface = defaultIfaceName()
|
||||||
// See corresponding comments in (*prog).setDNS function.
|
// See corresponding comments in (*prog).setDNS function.
|
||||||
allIfaces = requiredMultiNICsConfig()
|
allIfaces = requiredMultiNICsConfig()
|
||||||
}
|
}
|
||||||
logger := mainLog.Load().With().Str("iface", iface).Logger()
|
logger := mainLog.Load().With().Str("iface", runningIface).Logger()
|
||||||
netIface, err := netInterface(iface)
|
netIface, err := netInterface(runningIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Err(err).Msg("could not get interface")
|
logger.Error().Err(err).Msg("could not get interface")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user