From 60e5ff7ede1f314cfb3477118bcb08dc6467db21 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Thu, 31 Mar 2016 11:07:35 -0700 Subject: [PATCH] Fix problems loading external services on boot (like ubuntu-console or kernel-headers) On arm64 external services would not load on boot because of DNS i/o timeouts or valid TLS certificates appearing expired or not issued yet (I know that sounds weird). --- compose/project.go | 2 +- os-config.tpl.yml | 4 ++-- scripts/run | 1 + util/util.go | 12 +++++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compose/project.go b/compose/project.go index 14552a38..e64a2058 100644 --- a/compose/project.go +++ b/compose/project.go @@ -177,7 +177,7 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj go func() { for event := range projectEvents { - if event.EventType == project.EventContainerStarted && event.ServiceName == "network" { + if event.EventType == project.EventContainerStarted && event.ServiceName == "ntp" { network = true } } diff --git a/os-config.tpl.yml b/os-config.tpl.yml index 54438df3..2346cac0 100644 --- a/os-config.tpl.yml +++ b/os-config.tpl.yml @@ -105,7 +105,7 @@ rancher: io.rancher.os.detach: "false" io.rancher.os.reloadconfig: "true" io.rancher.os.scope: system - io.rancher.os.after: cloud-init-pre, wait-for-network + io.rancher.os.after: cloud-init-pre, wait-for-network, ntp net: host uts: host privileged: true @@ -207,7 +207,7 @@ rancher: image: {{.OS_IMAGES_ROOT}}/os-ntp:{{.VERSION}}{{.SUFFIX}} labels: io.rancher.os.scope: system - io.rancher.os.after: cloud-init, wait-for-network + io.rancher.os.after: wait-for-network net: host uts: host privileged: true diff --git a/scripts/run b/scripts/run index 0619c38f..96caa7b9 100755 --- a/scripts/run +++ b/scripts/run @@ -196,6 +196,7 @@ if [ "$QEMU" == "1" ]; then CPU="-cpu host" fi exec qemu-system-${QEMUARCH} -serial stdio \ + -rtc base=utc,clock=host \ ${KVM_ENABLE} \ ${CPU} \ ${machine["$ARCH"]} \ diff --git a/util/util.go b/util/util.go index f903e470..0048097c 100644 --- a/util/util.go +++ b/util/util.go @@ -274,6 +274,16 @@ func DirLs(dir string) ([]interface{}, error) { return result, nil } +func retryHttp(f func() (*http.Response, error), times int) (resp *http.Response, err error) { + for i := 0; i < times; i++ { + if resp, err = f(); err == nil { + return + } + log.Warnf("Error making HTTP request: %s. Retrying", err) + } + return +} + func LoadResource(location string, network bool, urls []string) ([]byte, error) { var bytes []byte err := ErrNotFound @@ -282,7 +292,7 @@ func LoadResource(location string, network bool, urls []string) ([]byte, error) if !network { return nil, ErrNoNetwork } - resp, err := http.Get(location) + resp, err := retryHttp(func() (*http.Response, error) { return http.Get(location) }, 8) if err != nil { return nil, err }