forked from chef/chef-load
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (60 loc) · 1.41 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
)
const AppVersion = "0.1.1"
var quit = make(chan int)
func main() {
fConfig := flag.String("config", "", "Configuration file to load")
fHelp := flag.Bool("help", false, "Print this help")
fNodes := flag.String("nodes", "", "Number of nodes making chef-client runs")
fRuns := flag.String("runs", "", "Number of chef-client runs each node should make, 0 value will make infinite runs")
fSampleConfig := flag.Bool("sample-config", false, "Print out full sample configuration")
fVersion := flag.Bool("version", false, "Print chef-load version")
flag.Parse()
if *fHelp {
fmt.Println("Usage of chef-load:")
flag.PrintDefaults()
os.Exit(0)
}
if *fVersion {
fmt.Println("chef-load", AppVersion)
os.Exit(0)
}
if *fSampleConfig {
printSampleConfig()
os.Exit(0)
}
var (
config *chefLoadConfig
err error
)
if *fConfig != "" {
config, err = loadConfig(*fConfig)
if err != nil {
log.Fatal(err)
}
} else {
fmt.Println("Usage of chef-load:")
flag.PrintDefaults()
return
}
if *fNodes != "" {
config.Nodes, _ = strconv.Atoi(*fNodes)
}
if *fRuns != "" {
config.Runs, _ = strconv.Atoi(*fRuns)
}
numNodes := config.Nodes
for i := 0; i < numNodes; i++ {
nodeName := config.NodeNamePrefix + "-" + strconv.Itoa(i)
go startNode(nodeName, *config)
}
for i := 0; i < numNodes; i++ {
<-quit // Wait to be told to exit.
}
}