Do not reload NGINX if master process dies
This commit is contained in:
parent
157cc5066c
commit
ea85404acd
2 changed files with 2 additions and 52 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue