Skip to content

Commit

Permalink
restart service on win (in place of systemd stuff ™️)
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Jan 12, 2025
1 parent 540d5e6 commit 07b1cc5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions subsystems/viamagent/viamagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ func (a *agentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf
return false, nil
}

expectedPath := filepath.Join(agent.ViamDirs["bin"], subsysName)
if runtime.GOOS == "windows" {
// no systemd on windows
// no systemd on windows -- check if binary is runnable, then restart service.
if err := exec.Command(expectedPath, "--version").Wait(); err != nil {

Check failure on line 75 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")
}
// note: sc.exe doesn't have a restart command it seems.
if err := exec.Command("powershell", "-command", "Restart-Service viam-agent").Wait(); err != nil {
return false, errw.Wrap(err, "restarting windows service")
}
return true, nil
}
expectedPath := filepath.Join(agent.ViamDirs["bin"], subsysName)

// Run the newly updated version to install systemd and other service files.
// Note: this also restarts the daemon.
//nolint:gosec
cmd := exec.Command(expectedPath, "--install")
output, err := cmd.CombinedOutput()
Expand All @@ -88,6 +96,7 @@ func (a *agentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf
return true, nil
}

// Install installs systemd and restarts the daemon.
func Install(logger logging.Logger) error {
// Check for systemd
cmd := exec.Command("systemctl", "--version")
Expand Down

0 comments on commit 07b1cc5

Please sign in to comment.