@@ -11,22 +11,22 @@ import (
11
11
"runtime"
12
12
"strings"
13
13
14
- "github.com/kardianos/service"
15
-
16
14
"github.com/jaypipes/ghw"
15
+ "github.com/kardianos/service"
17
16
"github.com/otiai10/copy"
18
17
"github.com/schollz/progressbar/v3"
19
18
20
19
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
21
20
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
21
+ "github.com/elastic/elastic-agent/internal/pkg/cli"
22
22
)
23
23
24
24
const (
25
25
darwin = "darwin"
26
26
)
27
27
28
28
// Install installs Elastic Agent persistently on the system including creating and starting its service.
29
- func Install (cfgFile , topPath string , pt * progressbar.ProgressBar ) error {
29
+ func Install (cfgFile , topPath string , pt * progressbar.ProgressBar , streams * cli. IOStreams ) error {
30
30
dir , err := findDirectory ()
31
31
if err != nil {
32
32
return errors .New (err , "failed to discover the source directory for installation" , errors .TypeFilesystem )
@@ -62,15 +62,18 @@ func Install(cfgFile, topPath string, pt *progressbar.ProgressBar) error {
62
62
}
63
63
64
64
// copy source into install path
65
- block , err := ghw .Block ()
66
- if err != nil {
67
- return fmt .Errorf ("ghw.Block() returned error: %w" , err )
68
- }
69
-
65
+ //
66
+ // Try to detect if we are running with SSDs. If we are increase the copy concurrency,
67
+ // otherwise fall back to the default.
70
68
copyConcurrency := 1
71
- if HasAllSSDs (* block ) {
69
+ hasSSDs , detectHWErr := HasAllSSDs ()
70
+ if detectHWErr != nil {
71
+ fmt .Fprintf (streams .Out , "Could not determine block hardware type, disabling copy concurrency: %s\n " , detectHWErr )
72
+ }
73
+ if hasSSDs {
72
74
copyConcurrency = runtime .NumCPU () * 4
73
75
}
76
+
74
77
pt .Describe ("Copying install files" )
75
78
err = copy .Copy (dir , topPath , copy.Options {
76
79
OnSymlink : func (_ string ) copy.SymlinkAction {
@@ -84,7 +87,8 @@ func Install(cfgFile, topPath string, pt *progressbar.ProgressBar) error {
84
87
return errors .New (
85
88
err ,
86
89
fmt .Sprintf ("failed to copy source directory (%s) to destination (%s)" , dir , topPath ),
87
- errors .M ("source" , dir ), errors .M ("destination" , topPath ))
90
+ errors .M ("source" , dir ), errors .M ("destination" , topPath ),
91
+ )
88
92
}
89
93
pt .Describe ("Successfully copied files" )
90
94
@@ -263,8 +267,22 @@ func verifyDirectory(dir string) error {
263
267
}
264
268
265
269
// HasAllSSDs returns true if the host we are on uses SSDs for
266
- // all its persistent storage; false otherwise or on error
267
- func HasAllSSDs (block ghw.BlockInfo ) bool {
270
+ // all its persistent storage; false otherwise. Returns any error
271
+ // encountered detecting the hardware type for informational purposes.
272
+ // Errors from this function are not fatal. Note that errors may be
273
+ // returned on some Mac hardware configurations as the ghw package
274
+ // does not fully support MacOS.
275
+ func HasAllSSDs () (bool , error ) {
276
+ block , err := ghw .Block ()
277
+ if err != nil {
278
+ return false , err
279
+ }
280
+
281
+ return hasAllSSDs (* block ), nil
282
+ }
283
+
284
+ // Internal version of HasAllSSDs for testing.
285
+ func hasAllSSDs (block ghw.BlockInfo ) bool {
268
286
for _ , disk := range block .Disks {
269
287
switch disk .DriveType {
270
288
case ghw .DRIVE_TYPE_FDD , ghw .DRIVE_TYPE_ODD :
0 commit comments