From 0e67efa56b933b669b2a4bc2d51e0fe245a27572 Mon Sep 17 00:00:00 2001 From: James Otting Date: Thu, 21 Nov 2024 17:30:02 -0500 Subject: [PATCH] Fix viam-server check-restart behavior (and version logging) --- subsystem.go | 4 +--- subsystems/viamserver/viamserver.go | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/subsystem.go b/subsystem.go index 5f252e1..013a795 100644 --- a/subsystem.go +++ b/subsystem.go @@ -345,16 +345,14 @@ func (s *AgentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf } // update current and previous versions - var previousVersion string if s.CacheData.CurrentVersion != s.CacheData.PreviousVersion { - previousVersion = s.CacheData.PreviousVersion s.CacheData.PreviousVersion = s.CacheData.CurrentVersion } s.CacheData.CurrentVersion = updateInfo.GetVersion() verData.Installed = time.Now() // if we made it here we performed an update and need to restart - s.logger.Infof("%s updated from %s to %s", s.name, previousVersion, verData.Version) + s.logger.Infof("%s updated from %s to %s", s.name, s.CacheData.PreviousVersion, s.CacheData.CurrentVersion) needRestart = true // record the cache diff --git a/subsystems/viamserver/viamserver.go b/subsystems/viamserver/viamserver.go index a478a95..efbba06 100644 --- a/subsystems/viamserver/viamserver.go +++ b/subsystems/viamserver/viamserver.go @@ -313,9 +313,9 @@ func (s *viamServer) isRestartAllowed(ctx context.Context) (bool, error) { ctx, cancelFunc := context.WithTimeout(ctx, time.Second*10) defer cancelFunc() - url += "/restart_status" + restartURL := url + "/restart_status" - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, restartURL, nil) if err != nil { return false, errw.Wrapf(err, "checking whether %s allows restart", SubsysName) } @@ -326,6 +326,11 @@ func (s *viamServer) isRestartAllowed(ctx context.Context) (bool, error) { resp, err := client.Do(req) if err != nil { + if url == s.checkURL { + // if this is only the first URL, we want to continue, not return, so log the error + s.logger.Warn(errw.Wrapf(err, "checking whether %s allows restart", SubsysName)) + continue + } return false, errw.Wrapf(err, "checking whether %s allows restart", SubsysName) }