()
| 438 | } |
| 439 | |
| 440 | func (a *application) graceRestart() { |
| 441 | pid := os.Getpid() |
| 442 | TLOG.Debugf("grace restart server begin %d", pid) |
| 443 | _ = os.Setenv("GRACE_RESTART", "1") |
| 444 | envs := os.Environ() |
| 445 | newEnvs := make([]string, 0) |
| 446 | for _, env := range envs { |
| 447 | // skip fd inherited from parent process |
| 448 | if strings.HasPrefix(env, grace.InheritFdPrefix) { |
| 449 | continue |
| 450 | } |
| 451 | newEnvs = append(newEnvs, env) |
| 452 | } |
| 453 | |
| 454 | // redirect stdout/stderr to logger |
| 455 | svrCfg := a.ServerConfig() |
| 456 | var logfile *os.File |
| 457 | if svrCfg != nil { |
| 458 | GetLogger("") |
| 459 | logpath := filepath.Join(svrCfg.LogPath, svrCfg.App, svrCfg.Server, svrCfg.App+"."+svrCfg.Server+".log") |
| 460 | logfile, _ = os.OpenFile(logpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) |
| 461 | TLOG.Debugf("redirect to %s %v", logpath, logfile) |
| 462 | } |
| 463 | if logfile == nil { |
| 464 | logfile = os.Stdout |
| 465 | } |
| 466 | files := []*os.File{os.Stdin, logfile, logfile} |
| 467 | for key, file := range grace.GetAllListenFiles() { |
| 468 | fd := fmt.Sprint(file.Fd()) |
| 469 | newFd := len(files) |
| 470 | TLOG.Debugf("translate %s=%s to %s=%d", key, fd, key, newFd) |
| 471 | newEnvs = append(newEnvs, fmt.Sprintf("%s=%d", key, newFd)) |
| 472 | files = append(files, file) |
| 473 | } |
| 474 | |
| 475 | exePath, err := exec.LookPath(os.Args[0]) |
| 476 | if err != nil { |
| 477 | TLOG.Errorf("LookPath failed %v", err) |
| 478 | return |
| 479 | } |
| 480 | |
| 481 | process, err := os.StartProcess(exePath, os.Args, &os.ProcAttr{ |
| 482 | Env: newEnvs, |
| 483 | Files: files, |
| 484 | }) |
| 485 | if err != nil { |
| 486 | TLOG.Errorf("start subprocess failed %v", err) |
| 487 | return |
| 488 | } |
| 489 | TLOG.Infof("subprocess start %d", process.Pid) |
| 490 | go process.Wait() |
| 491 | } |
| 492 | |
| 493 | func (a *application) graceShutdown() { |
| 494 | var wg sync.WaitGroup |
no test coverage detected