forked from kubeedge/kubeedge
/
pacmaninstaller.go
96 lines (79 loc) · 2.81 KB
/
pacmaninstaller.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package util
import (
"fmt"
"github.com/blang/semver"
types "github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/common"
)
// PacmanOS struct objects shall have information of the tools version to be installed
// on Hosts having PacmanOS.
// It implements OSTypeInstaller interface
type PacmanOS struct {
KubeEdgeVersion semver.Version
IsEdgeNode bool
}
// SetKubeEdgeVersion sets the KubeEdge version for the objects instance
func (o *PacmanOS) SetKubeEdgeVersion(version semver.Version) {
o.KubeEdgeVersion = version
}
// InstallMQTT checks if MQTT is already installed and running, if not then install it from OS repo
func (o *PacmanOS) InstallMQTT() error {
cmd := NewCommand("ps aux |awk '/mosquitto/ {print $1}' | awk '/mosquit/ {print}'")
if err := cmd.Exec(); err != nil {
return err
}
if stdout := cmd.GetStdOut(); stdout != "" {
fmt.Println("Host has", stdout, "already installed and running. Hence skipping the installation steps !!!")
return nil
}
// Install mqttInst
cmd = NewCommand("pacman -Syy --noconfirm mosquitto")
if err := cmd.Exec(); err != nil {
return err
}
fmt.Println(cmd.GetStdOut())
fmt.Println("MQTT is installed in this host")
return nil
}
// IsK8SComponentInstalled checks if said K8S version is already installed in the host
func (o *PacmanOS) IsK8SComponentInstalled(kubeConfig, master string) error {
return isK8SComponentInstalled(kubeConfig, master)
}
// InstallKubeEdge downloads the provided version of KubeEdge.
// Untar's in the specified location /etc/kubeedge/ and then copies
// the binary to excecutables' path (eg: /usr/local/bin)
func (o *PacmanOS) InstallKubeEdge(options types.InstallOptions) error {
arch := "amd64"
cmd := NewCommand("uname -m")
if err := cmd.Exec(); err != nil {
return err
}
result := cmd.GetStdOut()
switch result {
case "armv7l":
arch = OSArchARM32
case "aarch64":
arch = OSArchARM64
case "x86_64":
arch = OSArchAMD64
default:
return fmt.Errorf("can't support this architecture of PacmanOS: %s", result)
}
return installKubeEdge(options, arch, o.KubeEdgeVersion)
}
// RunEdgeCore sets the environment variable GOARCHAIUS_CONFIG_PATH for the configuration path
// and the starts edgecore with logs being captured
func (o *PacmanOS) RunEdgeCore() error {
return runEdgeCore(o.KubeEdgeVersion)
}
// KillKubeEdgeBinary will search for KubeEdge process and forcefully kill it
func (o *PacmanOS) KillKubeEdgeBinary(proc string) error {
return killKubeEdgeBinary(proc)
}
// IsKubeEdgeProcessRunning checks if the given process is running or not
func (o *PacmanOS) IsKubeEdgeProcessRunning(proc string) (bool, error) {
return isKubeEdgeProcessRunning(proc)
}
// IsKubeEdgeProcessRunning checks if the given process is running or not
func (o *PacmanOS) IsProcessRunning(proc string) (bool, error) {
return isKubeEdgeProcessRunning(proc)
}