mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
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:
+9
-2
@@ -1807,10 +1807,17 @@ func resetDnsTask(p *prog, s service.Service, isCtrldInstalled bool, ir *ifaceRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doValidateCdRemoteConfig fetches and validates custom config for cdUID.
|
// 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)
|
rc, err := controld.FetchResolverConfig(cdUID, rootCmd.Version, cdDev)
|
||||||
if err != nil {
|
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.
|
// validateCdRemoteConfig clobbers v, saving it here to restore later.
|
||||||
oldV := v
|
oldV := v
|
||||||
|
|||||||
+10
-11
@@ -373,7 +373,7 @@ NOTE: running "ctrld start" without any arguments will start already installed c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cdUID != "" {
|
if cdUID != "" {
|
||||||
doValidateCdRemoteConfig(cdUID)
|
doValidateCdRemoteConfig(cdUID, true)
|
||||||
} else if uid := cdUIDFromProvToken(); uid != "" {
|
} else if uid := cdUIDFromProvToken(); uid != "" {
|
||||||
cdUID = uid
|
cdUID = uid
|
||||||
mainLog.Load().Debug().Msg("using uid from provision token")
|
mainLog.Load().Debug().Msg("using uid from provision token")
|
||||||
@@ -698,7 +698,7 @@ func initRestartCmd() *cobra.Command {
|
|||||||
initInteractiveLogging()
|
initInteractiveLogging()
|
||||||
|
|
||||||
if cdMode {
|
if cdMode {
|
||||||
doValidateCdRemoteConfig(cdUID)
|
doValidateCdRemoteConfig(cdUID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ir := runningIface(s); ir != nil {
|
if ir := runningIface(s); ir != nil {
|
||||||
@@ -751,17 +751,16 @@ func initRestartCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if doRestart() {
|
if doRestart() {
|
||||||
dir, err := socketDir()
|
if dir, err := socketDir(); err == nil {
|
||||||
if 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")
|
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")
|
mainLog.Load().Notice().Msg("Service restarted")
|
||||||
} else {
|
} else {
|
||||||
mainLog.Load().Error().Msg("Service restart failed")
|
mainLog.Load().Error().Msg("Service restart failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user