1
0
mirror of https://github.com/rancher/os.git synced 2025-09-04 16:21:07 +00:00

Risky: remove 50s for loop delay on network failure (I think its remplaced by the dhcpcd --wait)

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-07-11 18:03:38 +10:00
parent 33a60488cd
commit 3b4d73e106
6 changed files with 67 additions and 49 deletions

View File

@@ -208,7 +208,7 @@ func IsLocalOrURL(service string) bool {
return isLocal(service) || strings.HasPrefix(service, "http:/") || strings.HasPrefix(service, "https:/") return isLocal(service) || strings.HasPrefix(service, "http:/") || strings.HasPrefix(service, "https:/")
} }
// Check to see if the service definition exists // ValidService checks to see if the service definition exists
func ValidService(service string, cfg *config.CloudConfig) bool { func ValidService(service string, cfg *config.CloudConfig) bool {
services := availableService(cfg) services := availableService(cfg)
if !IsLocalOrURL(service) && !util.Contains(services, service) { if !IsLocalOrURL(service) && !util.Contains(services, service) {

View File

@@ -224,19 +224,20 @@ func RunInit() error {
boot2DockerEnvironment := false boot2DockerEnvironment := false
var shouldSwitchRoot bool var shouldSwitchRoot bool
hypervisor := ""
configFiles := make(map[string][]byte) configFiles := make(map[string][]byte)
initFuncs := []config.CfgFuncData{ initFuncs := []config.CfgFuncData{
config.CfgFuncData{"preparefs", func(c *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"preparefs", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
return c, dfs.PrepareFs(&mountConfig) return cfg, dfs.PrepareFs(&mountConfig)
}}, }},
config.CfgFuncData{"save init cmdline", func(c *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"save init cmdline", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
// will this be passed to cloud-init-save? // will this be passed to cloud-init-save?
cmdLineArgs := strings.Join(os.Args, " ") cmdLineArgs := strings.Join(os.Args, " ")
config.SaveInitCmdline(cmdLineArgs) config.SaveInitCmdline(cmdLineArgs)
return c, nil return cfg, nil
}}, }},
config.CfgFuncData{"mount OEM", mountOem}, config.CfgFuncData{"mount OEM", mountOem},
config.CfgFuncData{"debug save cfg", func(_ *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"debug save cfg", func(_ *config.CloudConfig) (*config.CloudConfig, error) {
@@ -294,6 +295,7 @@ func RunInit() error {
config.CfgFuncData{"mount and bootstrap", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"mount and bootstrap", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
var err error var err error
cfg, shouldSwitchRoot, err = tryMountAndBootstrap(cfg) cfg, shouldSwitchRoot, err = tryMountAndBootstrap(cfg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -301,7 +303,7 @@ func RunInit() error {
}}, }},
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
hypervisor := checkHypervisor(cfg) hypervisor = checkHypervisor(cfg)
if hypervisor == "vmware" { if hypervisor == "vmware" {
// add vmware to the end - we don't want to over-ride an choices the user has made // add vmware to the end - we don't want to over-ride an choices the user has made
cfg.Rancher.CloudInit.Datasources = append(cfg.Rancher.CloudInit.Datasources, hypervisor) cfg.Rancher.CloudInit.Datasources = append(cfg.Rancher.CloudInit.Datasources, hypervisor)
@@ -368,8 +370,12 @@ func RunInit() error {
return cfg, nil return cfg, nil
}}, }},
config.CfgFuncData{"hypervisor tools", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
// Maybe we could set `rancher.hypervisor_service`, and defer this further?
enableHypervisorService(hypervisor)
return config.LoadConfig(), nil
}},
config.CfgFuncData{"b2d Env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"b2d Env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if boot2DockerEnvironment { if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil { if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err) log.Errorf("Failed to update rancher.state.dev: %v", err)
@@ -381,13 +387,13 @@ func RunInit() error {
return config.LoadConfig(), nil return config.LoadConfig(), nil
}}, }},
config.CfgFuncData{"preparefs2", func(c *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"preparefs2", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
return c, dfs.PrepareFs(&mountConfig) return cfg, dfs.PrepareFs(&mountConfig)
}}, }},
config.CfgFuncData{"load modules2", loadModules}, config.CfgFuncData{"load modules2", loadModules},
config.CfgFuncData{"set proxy env", func(c *config.CloudConfig) (*config.CloudConfig, error) { config.CfgFuncData{"set proxy env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
network.SetProxyEnvironmentVariables(c) network.SetProxyEnvironmentVariables(cfg)
return c, nil return cfg, nil
}}, }},
config.CfgFuncData{"init SELinux", initializeSelinux}, config.CfgFuncData{"init SELinux", initializeSelinux},
config.CfgFuncData{"setupSharedRoot", setupSharedRoot}, config.CfgFuncData{"setupSharedRoot", setupSharedRoot},
@@ -412,24 +418,33 @@ func RunInit() error {
} }
func checkHypervisor(cfg *config.CloudConfig) string { func checkHypervisor(cfg *config.CloudConfig) string {
hvtools := cpuid.CPU.HypervisorName if cpuid.CPU.HypervisorName == "" {
if hvtools == "" {
log.Infof("ros init: No Detected Hypervisor") log.Infof("ros init: No Detected Hypervisor")
} else { } else {
log.Infof("ros init: Detected Hypervisor: %s", cpuid.CPU.HypervisorName) log.Infof("ros init: Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
if hvtools == "vmware" {
hvtools = "open"
}
serviceName := hvtools + "-vm-tools"
// check quickly to see if there is a yml file available
if service.ValidService(serviceName, cfg) {
log.Infof("Setting rancher.services_include. %s=true", serviceName)
if err := config.Set("rancher.services_include."+serviceName, "true"); err != nil {
log.Error(err)
}
} else {
log.Infof("Skipping %s, can't get %s.yml file", serviceName, serviceName)
}
} }
return cpuid.CPU.HypervisorName return cpuid.CPU.HypervisorName
} }
func enableHypervisorService(hypervisorName string) {
if hypervisorName == "" {
return
}
if hypervisorName == "vmware" {
hypervisorName = "open"
}
serviceName := hypervisorName + "-vm-tools"
// check quickly to see if there is a yml file available
cfg := config.LoadConfig()
if service.ValidService(serviceName, cfg) {
log.Infof("Setting rancher.services_include. %s=true", serviceName)
log.Debugf("SVEN Setting rancher.services_include. %s=true", serviceName)
if err := config.Set("rancher.services_include."+serviceName, "true"); err != nil {
log.Error(err)
}
} else {
log.Infof("SVEN Skipping %s, can't get %s.yml file", serviceName, serviceName)
log.Debugf("SVEN Skipping %s, can't get %s.yml file", serviceName, serviceName)
}
}

View File

@@ -1 +1 @@
APPEND rancher.autologin=tty1 rancher.autologin=ttyS0 console=tty0 rancher.autologin=ttyS1 rancher.console=ttyS1 console=ttyS0 printk.devkmsg=on ${APPEND} APPEND rancher.autologin=tty1 rancher.autologin=ttyS0 console=tty0 rancher.autologin=ttyS1 printk.devkmsg=on ${APPEND}

View File

@@ -277,7 +277,7 @@ if [ "$GUICONSOLE" == "" ]; then
if [ "$NETCONSOLE" == "1" ]; then if [ "$NETCONSOLE" == "1" ]; then
# put ttyS1 on port 4444 # put ttyS1 on port 4444
DISPLAY_OPTS="${DISPLAY_OPTS} -serial tcp::4444,server" DISPLAY_OPTS="${DISPLAY_OPTS} -serial tcp::4444,server"
KERNEL_ARGS="rancher.console=ttyS1 rancher.autologin=ttyS1 ${KERNEL_ARGS}" KERNEL_ARGS="console=ttyS1 rancher.autologin=ttyS1 ${KERNEL_ARGS}"
fi fi
fi fi

View File

@@ -201,7 +201,7 @@ sudo ros service start network
sleep 1 sleep 1
ip a ip a
echo "===================" echo "==================="
sudo ros install --force --no-reboot --device /dev/vda -c config.yml -a "console=ttyS0 rancher.console=ttyS0 rancher.autologin=ttyS0 rancher.console=ttyS1 rancher.autologin=ttyS1 rancher.debug=true" sudo ros install --force --no-reboot --device /dev/vda -c config.yml -a "console=ttyS0 rancher.autologin=ttyS0 console=ttyS1 rancher.autologin=ttyS1 rancher.debug=true"
sync sync
`) `)
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)

View File

@@ -7,7 +7,6 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"time"
yaml "github.com/cloudfoundry-incubator/candiedyaml" yaml "github.com/cloudfoundry-incubator/candiedyaml"
@@ -89,29 +88,33 @@ func loadFromNetwork(location string) ([]byte, error) {
SetProxyEnvironmentVariables(cfg) SetProxyEnvironmentVariables(cfg)
var err error var err error
for i := 0; i < 300; i++ { // Sven thinks that the dhcpcd --wait we added makes this less necessary
updateDNSCache() //for i := 0; i < 300; i++ {
updateDNSCache()
var resp *http.Response var resp *http.Response
resp, err = http.Get(location) log.Infof("LoadFromNetwork(%s)", location)
if err == nil { resp, err = http.Get(location)
defer resp.Body.Close() log.Debugf("LoadFromNetwork(%s) returned %v", resp)
if resp.StatusCode != http.StatusOK { log.Debugf("LoadFromNetwork(%s) error %v", err)
return nil, fmt.Errorf("non-200 http response: %d", resp.StatusCode) if err == nil {
} defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bytes, err := ioutil.ReadAll(resp.Body) return nil, fmt.Errorf("non-200 http response: %d", resp.StatusCode)
if err != nil {
return nil, err
}
cacheAdd(location, bytes)
return bytes, nil
} }
time.Sleep(100 * time.Millisecond) bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
cacheAdd(location, bytes)
return bytes, nil
} }
// time.Sleep(100 * time.Millisecond)
//}
return nil, err return nil, err
} }