nginx process的respawn和just_spawn 标志

respawn标记是挂了要不要重启,
启动worker进程都是设置respawn=1的(不管ngx_start_worker_processes用
NGX_PROCESS_RESPAWN还是NGX_PROCESS_JUST_RESPAWN)

如果worker进程的退出返回值是2,fatal error的话,则不重启了, 
if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) {
    ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
                 "%s %P exited with fatal code %d "
                 "and can not be respawn",
                 process, pid, WEXITSTATUS(status));
    ngx_processes[i].respawn = 0;
}

关于just_spawn则要从nginx配置重载说起: 
master收到SIGHUP信号时, signal_handler设置 ngx_reconfigure = 1,
然后在master进程循环里,检测到reconfigure = 1时, 
运行init_cycle(cycle), 然后启动新的worker进程: 
ngx_start_worker_processes(cycle, ccf->worker_processes,
                           NGX_PROCESS_JUST_RESPAWN);

然后对worker进程发送shutdown信号, gracefully关闭旧的worker进程:
ngx_signal_worker_processes(cycle, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));

该函数是对所有worker进程进行循环发信号的,所以要用一个标记just_spawn来标记刚生成的进程:
if (ngx_processes[i].just_spawn) {
      ngx_processes[i].just_spawn = 0;
      continue;
}

上面的NGX_PROCESS_JUST_RESPAWN会设置 ngx_processes[s].just_spawn = 1;

你可能感兴趣的:(nginx process的respawn和just_spawn 标志)