Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve NGINX start #403

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func main() {

var nginxAPI *plus.NginxAPIController
if *nginxPlus {
time.Sleep(500 * time.Millisecond)
httpClient := getSocketClient()
nginxAPI, err = plus.NewNginxAPIController(&httpClient, "http://nginx-plus-api/api", local)
if err != nil {
Expand Down
32 changes: 20 additions & 12 deletions internal/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,26 @@ func (nginx *Controller) Reload() error {

// Start starts NGINX
func (nginx *Controller) Start(done chan error) {
if !nginx.local {
cmd := exec.Command("nginx")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
glog.Fatalf("Failed to start nginx: %v", err)
}
go func() {
done <- cmd.Wait()
}()
} else {
glog.V(3).Info("Starting nginx")
glog.V(3).Info("Starting nginx")

if nginx.local {
return
}

cmd := exec.Command("nginx")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
glog.Fatalf("Failed to start nginx: %v", err)
}

go func() {
done <- cmd.Wait()
}()

err := nginx.verifyClient.WaitForCorrectVersion(nginx.configVersion)
if err != nil {
glog.Fatalf("Could not get newest config version: %v", err)
}
}

Expand Down
8 changes: 5 additions & 3 deletions internal/nginx/verify/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ func (c *Client) WaitForCorrectVersion(expectedVersion int) error {
// This value needs tuning.
maxRetries := 160
sleep := 25 * time.Millisecond
for i := 0; i < maxRetries; i++ {
for i := 1; i <= maxRetries; i++ {
time.Sleep(sleep)

version, err := c.GetConfigVersion()
if err != nil {
return fmt.Errorf("unable to fetch version: %v", err)
glog.V(3).Infof("Unable to fetch version: %v", err)
continue
}
if version == expectedVersion {
glog.V(3).Infof("success, version %v ensured. iterations: %v. took: %v", expectedVersion, i, time.Duration(i)*sleep)
return nil
}
time.Sleep(sleep)
}
return fmt.Errorf("could not get expected version: %v", expectedVersion)
}