Skip to content

Commit

Permalink
logger, sleep, exit
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Jan 13, 2025
1 parent 8e38aa7 commit 837af6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions subsystems/viamagent/viamagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ var (
serviceFileContents []byte
)

type agentSubsystem struct{}
type agentSubsystem struct {
logger logging.Logger
}

func NewSubsystem(ctx context.Context, logger logging.Logger, updateConf *pb.DeviceSubsystemConfig) (subsystems.Subsystem, error) {
return agent.NewAgentSubsystem(ctx, subsysName, logger, &agentSubsystem{})
return agent.NewAgentSubsystem(ctx, subsysName, logger, &agentSubsystem{logger: logger})
}

// Start does nothing (we're already running as we ARE the agent.)
Expand Down Expand Up @@ -72,13 +74,16 @@ func (a *agentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf

expectedPath := filepath.Join(agent.ViamDirs["bin"], subsysName)
if runtime.GOOS == "windows" {
a.logger.Info("windows postinstall")
// no systemd on windows -- for now you need to double-restart.
if _, err := exec.Command(expectedPath, "--version").Output(); err != nil {

Check failure on line 79 in subsystems/viamagent/viamagent.go

View workflow job for this annotation

GitHub Actions / Test lint and build

G204: Subprocess launched with variable (gosec)
return false, errw.Wrap(err, "testing binary")
}
a.logger.Info("windows okay test binary")
if err := agent.RequestRestart(); err != nil {
return false, err
}
a.logger.Info("windows requested restart")
return true, nil
}

Expand Down
4 changes: 4 additions & 0 deletions utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package agent

import (
"io/fs"
"os"
"syscall"
"time"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -48,5 +50,7 @@ func RequestRestart() error {
return errors.New("globalcancel is nil, can't restart")
}
GlobalCancel()
time.Sleep(5 * time.Second) // todo: rearchitect to wait for exit
os.Exit(1) // non-zero exit code to trigger service restart; test whether this is necessary
return nil
}

0 comments on commit 837af6a

Please sign in to comment.