[FIX] fix bug: open() "/usr/local/openresty/nginx/html/update-upstreams" failed

This commit is contained in:
GLYASAI 2018-12-01 16:40:01 +08:00
parent aa19b9892b
commit cceb7e9c01

View File

@ -238,21 +238,22 @@ func (osvc *OrService) UpdatePools(pools []*v1.Pool) error {
}
upstream.Servers = append(upstream.Servers, server)
}
if len(upstream.Servers) == 0 {
continue
}
//if len(upstream.Servers) == 0 {
// continue
//}
upstreams = append(upstreams, upstream)
}
if len(upstreams) == 0 {
// TODO
return nil
}
//if len(upstreams) == 0 {
// logrus.Warningf("empty upstreams: %v", pools)
// return nil
//}
return osvc.updateUpstreams(upstreams)
}
// updateUpstreams updates the upstreams in ngx.shared.dict by post
func (osvc *OrService) updateUpstreams(upstream []*Upstream) error {
url := fmt.Sprintf("http://127.0.0.1:%v/update-upstreams", osvc.AuxiliaryPort)
osvc.WaitPluginReadyWithURL(url)
data, _ := json.Marshal(upstream)
logrus.Debugf("request contest of update-upstreams is %v", string(data))
@ -316,6 +317,19 @@ func (osvc *OrService) WaitPluginReady() {
}
}
// WaitPluginReady waits for the specified url to be ready
func (osvc *OrService) WaitPluginReadyWithURL(url string) {
for {
resp, err := http.Get(url)
if err == nil && resp.StatusCode == 200 {
logrus.Info("Nginx is ready")
break
}
logrus.Infof("Nginx is not ready yet: %v", err)
time.Sleep(1 * time.Second)
}
}
// newRbdServers creates new configuration file for Rainbond servers
func (osvc *OrService) newRbdServers() error {
cfgPath := "/run/nginx/rainbond"