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;
相關文章
相關標籤/搜索