From ea85404acd674b753850411eb95045525e0a8982 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Sun, 31 May 2020 12:54:51 -0400 Subject: [PATCH] Do not reload NGINX if master process dies --- internal/ingress/controller/nginx.go | 11 +---- internal/ingress/controller/process/nginx.go | 43 -------------------- 2 files changed, 2 insertions(+), 52 deletions(-) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index cec908065..af1e5027d 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -343,17 +343,10 @@ func (n *NGINXController) Start() { // issues because of this behavior. // To avoid this issue we restart nginx in case of errors. if process.IsRespawnIfRequired(err) { - process.WaitUntilPortIsAvailable(n.cfg.ListenPorts.HTTP) // release command resources - cmd.Process.Release() - // start a new nginx master process if the controller is not being stopped - cmd = n.command.ExecCommand() - cmd.SysProcAttr = &syscall.SysProcAttr{ - Setpgid: true, - Pgid: 0, - } - n.start(cmd) + return } + case event := <-n.updateCh.Out(): if n.isShuttingDown { break diff --git a/internal/ingress/controller/process/nginx.go b/internal/ingress/controller/process/nginx.go index a0aa44d90..69314441f 100644 --- a/internal/ingress/controller/process/nginx.go +++ b/internal/ingress/controller/process/nginx.go @@ -17,14 +17,9 @@ limitations under the License. package process import ( - "fmt" - "net" - "os" "os/exec" "syscall" - "time" - "github.com/ncabatoff/process-exporter/proc" "k8s.io/klog" ) @@ -43,41 +38,3 @@ NGINX master process died (%v): %v `, waitStatus.ExitStatus(), err) return true } - -// WaitUntilPortIsAvailable waits until there is no NGINX master or worker -// process/es listening in a particular port. -func WaitUntilPortIsAvailable(port int) { - // we wait until the workers are killed - for { - conn, err := net.DialTimeout("tcp", fmt.Sprintf("0.0.0.0:%v", port), 1*time.Second) - if err != nil { - break - } - conn.Close() - // kill nginx worker processes - fs, err := proc.NewFS("/proc", false) - if err != nil { - klog.Errorf("unexpected error reading /proc information: %v", err) - continue - } - - procs, _ := fs.FS.AllProcs() - for _, p := range procs { - pn, err := p.Comm() - if err != nil { - klog.Errorf("unexpected error obtaining process information: %v", err) - continue - } - - if pn == "nginx" { - osp, err := os.FindProcess(p.PID) - if err != nil { - klog.Errorf("unexpected error obtaining process information: %v", err) - continue - } - osp.Signal(syscall.SIGQUIT) - } - } - time.Sleep(100 * time.Millisecond) - } -}