-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathdeps_windows_amd64.go
More file actions
77 lines (66 loc) · 2.07 KB
/
Copy pathdeps_windows_amd64.go
File metadata and controls
77 lines (66 loc) · 2.07 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//go:build windows && amd64
// +build windows,amd64
package dependency
import (
"fmt"
"path/filepath"
"github.com/utmstack/UTMStack/agent/collector"
"github.com/utmstack/UTMStack/agent/config"
"github.com/utmstack/UTMStack/shared/exec"
"github.com/utmstack/UTMStack/shared/fs"
"github.com/utmstack/UTMStack/shared/svc"
)
// GetDependencies returns the list of dependencies for Windows amd64.
func GetDependencies() []Dependency {
basePath := fs.GetExecutablePath()
return []Dependency{
{
Name: "updater",
Version: getUpdaterVersion(),
BinaryPath: filepath.Join(basePath, UpdaterFile("")),
DownloadURL: func(server string) string {
return fmt.Sprintf(config.DependUrl, server, config.DependenciesPort, UpdaterFile(""))
},
Critical: false, // Agent can run without updater
PreDownload: preDownloadUpdater,
Configure: configureUpdater,
Uninstall: uninstallUpdater,
},
// New beats dependency - only for uninstalling existing filebeat/winlogbeat
// No download, no install - native collectors are used instead
{
Name: "beats",
Version: BeatsVersion,
Critical: false,
Uninstall: uninstallBeats,
},
}
}
func configureUpdater() error {
updaterPath := filepath.Join(fs.GetExecutablePath(), UpdaterFile(""))
return exec.Run(updaterPath, fs.GetExecutablePath(), "install")
}
func uninstallUpdater() error {
updaterPath := filepath.Join(fs.GetExecutablePath(), UpdaterFile(""))
if !fs.Exists(updaterPath) {
return nil
}
return exec.Run(updaterPath, fs.GetExecutablePath(), "uninstall")
}
func uninstallBeats() error {
return collector.UninstallAll()
}
func preDownloadUpdater() (func(), error) {
// Stop the updater service before download
if err := svc.Stop(config.SERVICE_UPDATER_NAME); err != nil {
// Service might not be running or installed yet - that's OK
// Return cleanup function anyway (safe to start)
return func() {
_ = svc.Start(config.SERVICE_UPDATER_NAME)
}, nil
}
// Return cleanup function that restarts the service
return func() {
_ = svc.Start(config.SERVICE_UPDATER_NAME)
}, nil
}