generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
staticbinary.go
48 lines (41 loc) · 990 Bytes
/
staticbinary.go
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
package autostartconf
import (
"path/filepath"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
)
type StaticBinaryConfigurer struct {
LinuxSystemdConfigurer
URL string
Name string
}
func (sbc StaticBinaryConfigurer) Install() error {
_ = sbc.UnInstall() // best effort
// download binary
err := sbc.Store.DownloadBinary(
sbc.URL,
filepath.Join("/usr/local/bin", sbc.Name),
)
if err != nil {
return breverrors.WrapAndTrace(err)
}
err = sbc.Store.WriteString(sbc.getDestConfigFile(), sbc.ValueConfigFile)
if err != nil {
return breverrors.WrapAndTrace(err)
}
if ShouldSymlink() {
errother := sbc.CreateForcedSymlink()
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
} else {
errother := ExecCommands([][]string{
{"systemctl", "enable", sbc.ServiceName},
{"systemctl", "start", sbc.ServiceName},
{"systemctl", "daemon-reload"},
})
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
}
return nil
}