forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·71 lines (59 loc) · 1.62 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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"github.com/Sirupsen/logrus"
"github.com/rancher/agent/cloudprovider/aws"
"github.com/rancher/agent/events"
"github.com/rancher/agent/register"
)
var (
VERSION = "dev"
)
func main() {
version := flag.Bool("version", false, "go-agent version")
rurl := flag.String("url", "", "registration url")
registerService := flag.String("register-service", "", "register rancher-agent service")
unregisterService := flag.Bool("unregister-service", false, "unregister rancher-agent service")
flag.Parse()
if *version {
fmt.Printf("go-agent version %s \n", VERSION)
os.Exit(0)
}
if runtime.GOOS != "windows" {
logrus.SetOutput(os.Stdout)
}
if os.Getenv("CATTLE_SCRIPT_DEBUG") != "" {
logrus.SetLevel(logrus.DebugLevel)
}
if err := register.Init(*registerService, *unregisterService); err != nil {
logrus.Fatalf("Failed to Initialize Service err: %v", err)
}
if err := register.DownloadAPICrt(); err != nil {
logrus.Fatalf("Exiting. Error: %v", err)
}
if *rurl == "" {
*rurl = os.Getenv("CATTLE_REGISTRATION_URL")
}
if *rurl != "" {
err := register.RunRegistration(*rurl)
if err != nil {
logrus.Errorf("registration failed. err: %v", err)
os.Exit(1)
}
}
logrus.Info("Launching agent")
url := os.Getenv("CATTLE_URL")
accessKey := os.Getenv("CATTLE_ACCESS_KEY")
secretKey := os.Getenv("CATTLE_SECRET_KEY")
workerCount := 1000
provider := aws.NewProvider()
go provider.GetCloudProviderInfo()
err := events.Listen(url, accessKey, secretKey, workerCount)
if err != nil {
logrus.Fatalf("Exiting. Error: %v", err)
register.NotifyShutdown(err)
}
}