This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minion.go
79 lines (65 loc) · 1.58 KB
/
minion.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
package main
import (
"fmt"
"log"
"net/rpc"
"strings"
"time"
"pault.ag/go/minion/minion"
"pault.ag/go/service"
)
var minionCommand = Command{
Name: "minion",
Run: minionRun,
Usage: ``,
}
var suites *string
func init() {
suites = minionCommand.Flag.String("suites", "", "comma seperated suite:arch pairs")
}
type minionService struct {
service.Node
Config minion.MinionConfig
}
func (m *minionService) Register() {
if *suites == "" {
log.Fatalf("No suites given\n")
}
buildableSuites := []minion.BuildableSuite{}
suitePairs := strings.Split(*suites, ",")
for _, suitePair := range suitePairs {
pair := strings.Split(suitePair, ":")
if len(pair) != 2 {
panic(fmt.Errorf("Error! %s is an invalid suite pair", suitePair))
}
buildableSuites = append(buildableSuites, minion.BuildableSuite{
Suite: pair[0],
Arch: pair[1],
})
}
minion := minion.NewMinionRemote(m.Config, buildableSuites)
rpc.Register(&minion)
}
func minionRunServe(config minion.MinionConfig) {
log.Printf("Diling coordinator\n")
conn, err := service.DialFromKeys(
fmt.Sprintf("%s:%d", config.Host, config.Port),
config.Cert, config.Key, config.CaCert,
)
if err != nil {
log.Printf("Error! %s\n", err)
return
}
log.Printf("Doing what they say!\n")
service.ServeConn(conn)
}
func minionRun(config minion.MinionConfig, cmd *Command, args []string) {
log.Printf("Bringing Minion online\n")
node := minionService{Config: config}
node.Register()
for {
minionRunServe(config)
log.Printf("System fell down. Crap. Waiting a minute and retyring")
time.Sleep(time.Second * 60)
}
}