Skip to content

Commit

Permalink
Fix viam-server check-restart behavior (and version logging)
Browse files Browse the repository at this point in the history
  • Loading branch information
Otterverse committed Nov 21, 2024
1 parent b19180f commit 0e67efa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 1 addition & 3 deletions subsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions subsystems/viamserver/viamserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down

0 comments on commit 0e67efa

Please sign in to comment.