forked from viamrobotics/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_linux.go
More file actions
44 lines (36 loc) · 1.08 KB
/
Copy pathagent_linux.go
File metadata and controls
44 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package agent
import (
"context"
_ "embed"
"os/exec"
"path/filepath"
errw "github.com/pkg/errors"
"github.com/viamrobotics/agent/utils"
"go.viam.com/rdk/logging"
rutils "go.viam.com/rdk/utils"
)
const (
serviceName = "viam-agent"
)
//go:embed viam-agent.service
var serviceFileContents []byte
// InstallNewVersion runs the newly downloaded binary's Install() for installation of systemd files and the like.
func InstallNewVersion(ctx context.Context, logger logging.Logger) (bool, error) {
expectedPath := filepath.Join(utils.ViamDirs.Bin, SubsystemName)
// Run the newly updated version to install systemd and other service files.
logger.Info("running viam-agent --install for new version")
cleanup := rutils.SlowLogger(
ctx,
"Waiting for new version of viam-agent to finish installing", "", "",
logger,
)
defer cleanup()
//nolint:gosec
cmd := exec.CommandContext(ctx, expectedPath, "--install")
output, err := cmd.CombinedOutput()
logger.Info(string(output))
if err != nil {
return false, errw.Wrapf(err, "error running install step %s", output)
}
return true, nil
}