From 7e1699cda0286e0a0fa4905a9fd54a45307b6def Mon Sep 17 00:00:00 2001 From: galal-hussein Date: Wed, 1 May 2019 22:54:05 +0200 Subject: [PATCH] Check if hostname is resolvable before running agent --- pkg/agent/config/config.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 1c689a1564..58684c8adb 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -253,6 +253,8 @@ func get(envInfo *cmds.Agent) (*config.Node, error) { return nil, err } + hostnameCheck(nodeName) + nodeCertFile := filepath.Join(envInfo.DataDir, "token-node.crt") nodeKeyFile := filepath.Join(envInfo.DataDir, "token-node.key") nodePasswordFile := filepath.Join(envInfo.DataDir, "node-password.txt") @@ -348,3 +350,14 @@ func getConfig(info *clientaccess.Info) (*config.Control, error) { controlControl := &config.Control{} return controlControl, json.Unmarshal(data, controlControl) } + +func hostnameCheck(hostname string) { + for { + _, err := sysnet.LookupHost(hostname) + if err == nil { + break + } + logrus.Infof("Waiting for hostname %s to be resolvable: %v", hostname, err) + time.Sleep(2 * time.Second) + } +}