ngx_add_inherited_sockets
尝试从环境变量NGINX中解析出父进程传入的listening fd;
变量值格式为’:’或’;’分隔的数字;
如果从父进程继承了listening fd,则ngx_inherited设置为1;
初始化模块的索引下标(ngx_module_t::index)以及ngx_max_module;
调用ngx_init_cycle函数
从old_cycle中拷贝conf_prefix,prefix, conf_file, conf_param等配置;
初始化paths,open_files, shared_memory, listening, reusable_connections_queue等容器(array&list&queue);
初始化conf_ctx数组,它是一个大小为ngx_max_module的void *类型数组,用来保存NGX_CORE_MODULE的context;
初始化hostname;
遍历core模块,调用create_conf回调函数,为其创建context,并保存在conf_ctx数组中下标为ngx_module_t::index的位置;
初始化ngx_conf_t,设置其module_type为NGX_CORE_MODULE,设置其cmd_type为NGX_MAIN_CONF;
调用ngx_conf_param解析conf_param变量;
调用ngx_conf_parse解析conf_file文件;
变量core模块,调用init_conf回调函数,初始化模块的context;
创建pid file,删除old pidfile;
遍历paths数组,创建路径;
初始化默认log;
遍历open_files链表,以append模式打开这些文件;
遍历shared_memory链表,创建共享内存,初始化共享内存池(ngx_init_zone_pool),优先考虑从old_cycle中继承配置相同的共享内存;
遍历listening数组,调用ngx_open_listening_sockets打开监听端口,优先考虑从old_cycle中继承配置相同的listening fd;
遍历所有模块,调用init_module回调函数;
释放old_cycle中无用的(未被继承使用)共享内存、listening fd;
关闭old_cycle中打开的文件;
将old_cycle加入延迟回收队列,30s后调用ngx_clean_old_cycles回收;
调用ngx_init_signals初始化信号处理器;
调用ngx_daemon;
创建pid file;
调用ngx_master_process_cycle启动worker和cache进程;