cmd/cli: make validating remote config non-fatal during restart

Since we already have a config on disk, it's better to enforce what we
have instead of fatal.
This commit is contained in:
Cuong Manh Le
2025-02-07 15:46:07 +07:00
committed by Cuong Manh Le
parent caf98b4dfe
commit 253a57ca01
2 changed files with 19 additions and 13 deletions

View File

@@ -1807,10 +1807,17 @@ func resetDnsTask(p *prog, s service.Service, isCtrldInstalled bool, ir *ifaceRe
}
// doValidateCdRemoteConfig fetches and validates custom config for cdUID.
func doValidateCdRemoteConfig(cdUID string) {
func doValidateCdRemoteConfig(cdUID string, fatal bool) {
rc, err := controld.FetchResolverConfig(cdUID, rootCmd.Version, cdDev)
if err != nil {
mainLog.Load().Fatal().Err(err).Msgf("failed to fetch resolver uid: %s", cdUID)
logger := mainLog.Load().Fatal()
if !fatal {
logger = mainLog.Load().Warn()
}
logger.Err(err).Err(err).Msgf("failed to fetch resolver uid: %s", cdUID)
if !fatal {
return
}
}
// validateCdRemoteConfig clobbers v, saving it here to restore later.
oldV := v

View File

@@ -373,7 +373,7 @@ NOTE: running "ctrld start" without any arguments will start already installed c
}
if cdUID != "" {
doValidateCdRemoteConfig(cdUID)
doValidateCdRemoteConfig(cdUID, true)
} else if uid := cdUIDFromProvToken(); uid != "" {
cdUID = uid
mainLog.Load().Debug().Msg("using uid from provision token")
@@ -698,7 +698,7 @@ func initRestartCmd() *cobra.Command {
initInteractiveLogging()
if cdMode {
doValidateCdRemoteConfig(cdUID)
doValidateCdRemoteConfig(cdUID, false)
}
if ir := runningIface(s); ir != nil {
@@ -751,17 +751,16 @@ func initRestartCmd() *cobra.Command {
}
if doRestart() {
dir, err := socketDir()
if err != nil {
if dir, err := socketDir(); err == nil {
cc := newSocketControlClient(context.TODO(), s, dir)
if cc == nil {
mainLog.Load().Error().Msg("Could not complete service restart")
os.Exit(1)
}
_, _ = cc.post(ifacePath, nil)
} else {
mainLog.Load().Warn().Err(err).Msg("Service was restarted, but could not ping the control server")
return
}
cc := newSocketControlClient(context.TODO(), s, dir)
if cc == nil {
mainLog.Load().Error().Msg("Could not complete service restart")
os.Exit(1)
}
_, _ = cc.post(ifacePath, nil)
mainLog.Load().Notice().Msg("Service restarted")
} else {
mainLog.Load().Error().Msg("Service restart failed")