Mercurial > hg > nginx
comparison src/os/unix/ngx_process_cycle.c @ 318:56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 16 Apr 2004 05:14:16 +0000 |
parents | 1308b98496a2 |
children | ab2f8c9a2a45 |
comparison
equal
deleted
inserted
replaced
317:1308b98496a2 | 318:56496082668b |
---|---|
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 | 5 |
6 #include <nginx.h> | 6 #include <nginx.h> |
7 | 7 |
8 | 8 |
9 static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n) | 9 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, |
10 ngx_int_t type); | |
11 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); | |
10 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); | 12 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); |
11 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 13 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
12 #if (NGX_THREADS) | 14 #if (NGX_THREADS) |
13 static int ngx_worker_thread_cycle(void *data); | 15 static int ngx_worker_thread_cycle(void *data); |
14 #endif | 16 #endif |
34 ngx_uint_t ngx_restart; | 36 ngx_uint_t ngx_restart; |
35 | 37 |
36 | 38 |
37 void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | 39 void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) |
38 { | 40 { |
39 int signo; | 41 ngx_uint_t i; |
40 sigset_t set; | 42 sigset_t set; |
41 struct timeval tv; | 43 struct timeval tv; |
42 struct itimerval itv; | 44 struct itimerval itv; |
43 ngx_uint_t i, live; | 45 ngx_uint_t live; |
44 ngx_msec_t delay; | 46 ngx_msec_t delay; |
45 ngx_core_conf_t *ccf; | 47 ngx_core_conf_t *ccf; |
46 | 48 |
47 sigemptyset(&set); | 49 sigemptyset(&set); |
48 sigaddset(&set, SIGCHLD); | 50 sigaddset(&set, SIGCHLD); |
64 | 66 |
65 ngx_setproctitle("master process"); | 67 ngx_setproctitle("master process"); |
66 | 68 |
67 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 69 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
68 | 70 |
69 ngx_start_worker_processes(ccf->worker_processes); | 71 ngx_start_worker_processes(cycle, ccf->worker_processes, |
72 NGX_PROCESS_RESPAWN); | |
70 | 73 |
71 ngx_new_binary = 0; | 74 ngx_new_binary = 0; |
72 delay = 0; | 75 delay = 0; |
73 signo = 0; | |
74 live = 1; | 76 live = 1; |
75 | 77 |
76 for ( ;; ) { | 78 for ( ;; ) { |
77 if (delay) { | 79 if (delay) { |
78 delay *= 2; | 80 delay *= 2; |
105 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap childs"); | 107 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap childs"); |
106 | 108 |
107 live = 0; | 109 live = 0; |
108 for (i = 0; i < ngx_last_process; i++) { | 110 for (i = 0; i < ngx_last_process; i++) { |
109 | 111 |
110 ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 112 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
111 "child: " PID_T_FMT " e:%d t:%d d:%d r:%d", | 113 "child: " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d", |
112 ngx_processes[i].pid, | 114 ngx_processes[i].pid, |
113 ngx_processes[i].exiting, | 115 ngx_processes[i].exiting, |
114 ngx_processes[i].exited, | 116 ngx_processes[i].exited, |
115 ngx_processes[i].detached, | 117 ngx_processes[i].detached, |
116 ngx_processes[i].respawn); | 118 ngx_processes[i].respawn, |
119 ngx_processes[i].just_respawn); | |
117 | 120 |
118 if (ngx_processes[i].exited) { | 121 if (ngx_processes[i].exited) { |
119 | 122 |
120 if (ngx_processes[i].respawn | 123 if (ngx_processes[i].respawn |
121 && !ngx_processes[i].exiting | 124 && !ngx_processes[i].exiting |
166 if (delay == 0) { | 169 if (delay == 0) { |
167 delay = 50; | 170 delay = 50; |
168 } | 171 } |
169 | 172 |
170 if (delay > 1000) { | 173 if (delay > 1000) { |
171 signo = SIGKILL; | 174 ngx_signal_worker_processes(cycle, SIGKILL); |
172 } else { | 175 } else { |
173 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); | 176 ngx_signal_worker_processes(cycle, |
174 } | 177 ngx_signal_value(NGX_TERMINATE_SIGNAL)); |
175 | 178 } |
176 } else if (ngx_quit) { | 179 |
177 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 180 continue; |
178 | 181 } |
179 } else if (ngx_timer) { | 182 |
180 ngx_start_worker_processes(ccf->worker_processes); | 183 if (ngx_quit) { |
181 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 184 ngx_signal_worker_processes(cycle, |
182 | 185 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); |
183 } else if (ngx_reconfigure) { | 186 continue; |
187 } | |
188 | |
189 if (ngx_timer) { | |
190 ngx_timer = 0; | |
191 ngx_start_worker_processes(cycle, ccf->worker_processes, | |
192 NGX_PROCESS_JUST_RESPAWN); | |
193 live = 1; | |
194 ngx_signal_worker_processes(cycle, | |
195 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | |
196 } | |
197 | |
198 if (ngx_reconfigure) { | |
199 ngx_reconfigure = 0; | |
184 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); | 200 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); |
185 | 201 |
186 cycle = ngx_init_cycle(cycle); | 202 cycle = ngx_init_cycle(cycle); |
187 if (cycle == NULL) { | 203 if (cycle == NULL) { |
188 cycle = (ngx_cycle_t *) ngx_cycle; | 204 cycle = (ngx_cycle_t *) ngx_cycle; |
190 } | 206 } |
191 | 207 |
192 ngx_cycle = cycle; | 208 ngx_cycle = cycle; |
193 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, | 209 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, |
194 ngx_core_module); | 210 ngx_core_module); |
195 ngx_start_worker_processes(ccf->worker_processes); | 211 ngx_start_worker_processes(cycle, ccf->worker_processes, |
196 | 212 NGX_PROCESS_JUST_RESPAWN); |
213 live = 1; | |
214 ngx_signal_worker_processes(cycle, | |
215 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | |
216 } | |
217 | |
218 if (ngx_restart) { | |
219 ngx_restart = 0; | |
220 ngx_start_worker_processes(cycle, ccf->worker_processes, | |
221 NGX_PROCESS_RESPAWN); | |
222 live = 1; | |
223 } | |
224 | |
225 if (ngx_reopen) { | |
226 ngx_reopen = 0; | |
227 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopening logs"); | |
228 ngx_reopen_files(cycle, ccf->user); | |
229 ngx_signal_worker_processes(cycle, | |
230 ngx_signal_value(NGX_REOPEN_SIGNAL)); | |
231 } | |
232 | |
233 if (ngx_change_binary) { | |
234 ngx_change_binary = 0; | |
235 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "changing binary"); | |
236 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); | |
237 } | |
238 | |
239 if (ngx_noaccept) { | |
240 ngx_noaccept = 0; | |
241 ngx_noaccepting = 1; | |
242 ngx_signal_worker_processes(cycle, | |
243 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | |
244 } | |
245 } | |
246 } | |
247 | |
248 | |
249 void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | |
250 { | |
251 ngx_uint_t i; | |
252 | |
253 ngx_setproctitle("single worker process"); | |
254 | |
255 ngx_init_temp_number(); | |
256 | |
257 for (i = 0; ngx_modules[i]; i++) { | |
258 if (ngx_modules[i]->init_process) { | |
259 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { | |
260 /* fatal */ | |
261 exit(2); | |
262 } | |
263 } | |
264 } | |
265 | |
266 for ( ;; ) { | |
267 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); | |
268 | |
269 ngx_process_events(cycle); | |
270 | |
271 if (ngx_terminate || ngx_quit) { | |
272 ngx_master_exit(cycle, ctx); | |
273 } | |
274 | |
275 if (ngx_reconfigure) { | |
197 ngx_reconfigure = 0; | 276 ngx_reconfigure = 0; |
198 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 277 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); |
199 | 278 |
200 } else if (ngx_restart) { | 279 cycle = ngx_init_cycle(cycle); |
201 ngx_start_worker_processes(ccf->worker_processes); | 280 if (cycle == NULL) { |
202 ngx_restart = 0; | 281 cycle = (ngx_cycle_t *) ngx_cycle; |
203 | 282 continue; |
204 } else if (ngx_reopen) { | 283 } |
205 if (ngx_process == NGX_PROCESS_MASTER) { | 284 |
206 signo = ngx_signal_value(NGX_REOPEN_SIGNAL); | 285 ngx_cycle = cycle; |
207 ngx_reopen = 0; | 286 } |
208 | 287 |
209 } else { /* NGX_PROCESS_SINGLE */ | 288 if (ngx_reopen) { |
210 ngx_reopen = 0; | 289 ngx_reopen = 0; |
211 } | 290 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopening logs"); |
212 | 291 ngx_reopen_files(cycle, (ngx_uid_t) -1); |
213 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 292 } |
214 "reopening logs"); | 293 } |
215 ngx_reopen_files(cycle, ccf->user); | 294 } |
216 | 295 |
217 } else if (ngx_change_binary) { | 296 |
218 ngx_change_binary = 0; | 297 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, |
219 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 298 ngx_int_t type) |
220 "changing binary"); | |
221 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); | |
222 | |
223 } else if (ngx_noaccept) { | |
224 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | |
225 } | |
226 } | |
227 | |
228 if (signo) { | |
229 for (i = 0; i < ngx_last_process; i++) { | |
230 | |
231 if (ngx_processes[i].detached) { | |
232 continue; | |
233 } | |
234 | |
235 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
236 "kill (" PID_T_FMT ", %d)" , | |
237 ngx_processes[i].pid, signo); | |
238 | |
239 if (kill(ngx_processes[i].pid, signo) == -1) { | |
240 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
241 "kill(%d, %d) failed", | |
242 ngx_processes[i].pid, signo); | |
243 continue; | |
244 } | |
245 | |
246 if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) { | |
247 ngx_processes[i].exiting = 1; | |
248 } | |
249 } | |
250 | |
251 signo = 0; | |
252 } | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 } | |
264 } | |
265 | |
266 | |
267 void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | |
268 { | |
269 int signo; | |
270 sigset_t set; | |
271 struct timeval tv; | |
272 struct itimerval itv; | |
273 ngx_uint_t i, live; | |
274 ngx_msec_t delay; | |
275 ngx_core_conf_t *ccf; | |
276 | |
277 if (ngx_process == NGX_PROCESS_MASTER) { | |
278 sigemptyset(&set); | |
279 sigaddset(&set, SIGCHLD); | |
280 sigaddset(&set, SIGALRM); | |
281 sigaddset(&set, SIGINT); | |
282 sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL)); | |
283 sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL)); | |
284 sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL)); | |
285 sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL)); | |
286 sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | |
287 sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL)); | |
288 | |
289 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { | |
290 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
291 "sigprocmask() failed"); | |
292 } | |
293 | |
294 sigemptyset(&set); | |
295 } | |
296 | |
297 ngx_setproctitle("master process"); | |
298 | |
299 ngx_new_binary = 0; | |
300 delay = 0; | |
301 signo = 0; | |
302 live = 0; | |
303 | |
304 for ( ;; ) { | |
305 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); | |
306 | |
307 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, | |
308 ngx_core_module); | |
309 | |
310 if (ngx_process == NGX_PROCESS_MASTER) { | |
311 for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) { | |
312 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | |
313 "worker process", NGX_PROCESS_RESPAWN); | |
314 } | |
315 | |
316 /* | |
317 * we have to limit the maximum life time of the worker processes | |
318 * by 10 days because our millisecond event timer is limited | |
319 * by 24 days on 32-bit platforms | |
320 */ | |
321 | |
322 itv.it_interval.tv_sec = 0; | |
323 itv.it_interval.tv_usec = 0; | |
324 itv.it_value.tv_sec = 10 * 24 * 60 * 60; | |
325 itv.it_value.tv_usec = 0; | |
326 | |
327 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { | |
328 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
329 "setitimer() failed"); | |
330 } | |
331 | |
332 live = 1; | |
333 | |
334 } else { | |
335 ngx_init_temp_number(); | |
336 | |
337 for (i = 0; ngx_modules[i]; i++) { | |
338 if (ngx_modules[i]->init_process) { | |
339 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { | |
340 /* fatal */ | |
341 exit(2); | |
342 } | |
343 } | |
344 } | |
345 } | |
346 | |
347 | |
348 /* a cycle with the same configuration because a new one is invalid */ | |
349 | |
350 for ( ;; ) { | |
351 | |
352 /* an event loop */ | |
353 | |
354 for ( ;; ) { | |
355 | |
356 if (ngx_process == NGX_PROCESS_MASTER) { | |
357 if (delay) { | |
358 delay *= 2; | |
359 | |
360 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
361 "temination cycle: %d", delay); | |
362 | |
363 itv.it_interval.tv_sec = 0; | |
364 itv.it_interval.tv_usec = 0; | |
365 itv.it_value.tv_sec = delay / 1000; | |
366 itv.it_value.tv_usec = (delay % 1000 ) * 1000; | |
367 | |
368 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { | |
369 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
370 "setitimer() failed"); | |
371 } | |
372 } | |
373 | |
374 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
375 "sigsuspend"); | |
376 | |
377 sigsuspend(&set); | |
378 | |
379 ngx_gettimeofday(&tv); | |
380 ngx_time_update(tv.tv_sec); | |
381 | |
382 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
383 "wake up"); | |
384 | |
385 } else { /* NGX_PROCESS_SINGLE */ | |
386 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
387 "worker cycle"); | |
388 | |
389 ngx_process_events(cycle); | |
390 live = 0; | |
391 } | |
392 | |
393 if (ngx_reap) { | |
394 ngx_reap = 0; | |
395 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
396 "reap childs"); | |
397 | |
398 live = 0; | |
399 for (i = 0; i < ngx_last_process; i++) { | |
400 | |
401 ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
402 "child: " PID_T_FMT | |
403 " e:%d t:%d d:%d r:%d", | |
404 ngx_processes[i].pid, | |
405 ngx_processes[i].exiting, | |
406 ngx_processes[i].exited, | |
407 ngx_processes[i].detached, | |
408 ngx_processes[i].respawn); | |
409 | |
410 if (ngx_processes[i].exited) { | |
411 | |
412 if (ngx_processes[i].respawn | |
413 && !ngx_processes[i].exiting | |
414 && !ngx_terminate | |
415 && !ngx_quit) | |
416 { | |
417 if (ngx_spawn_process(cycle, | |
418 ngx_processes[i].proc, | |
419 ngx_processes[i].data, | |
420 ngx_processes[i].name, i) | |
421 == NGX_ERROR) | |
422 { | |
423 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
424 "can not respawn %s", | |
425 ngx_processes[i].name); | |
426 continue; | |
427 } | |
428 | |
429 live = 1; | |
430 | |
431 continue; | |
432 } | |
433 | |
434 if (ngx_processes[i].pid == ngx_new_binary) { | |
435 ngx_new_binary = 0; | |
436 | |
437 /* TODO: if (ngx_noaccept) ngx_configure = 1 */ | |
438 } | |
439 | |
440 if (i != --ngx_last_process) { | |
441 ngx_processes[i--] = | |
442 ngx_processes[ngx_last_process]; | |
443 } | |
444 | |
445 } else if (ngx_processes[i].exiting | |
446 || !ngx_processes[i].detached) | |
447 { | |
448 live = 1; | |
449 } | |
450 } | |
451 } | |
452 | |
453 if (!live && (ngx_terminate || ngx_quit)) { | |
454 ngx_master_exit(cycle, ctx); | |
455 } | |
456 | |
457 if (ngx_terminate) { | |
458 if (delay == 0) { | |
459 delay = 50; | |
460 } | |
461 | |
462 if (delay > 1000) { | |
463 signo = SIGKILL; | |
464 } else { | |
465 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); | |
466 } | |
467 | |
468 } else if (ngx_quit) { | |
469 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | |
470 | |
471 } else if (ngx_timer) { | |
472 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | |
473 | |
474 } else if (ngx_reconfigure) { | |
475 ngx_reconfigure = 0; | |
476 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); | |
477 | |
478 cycle = ngx_init_cycle(cycle); | |
479 if (cycle == NULL) { | |
480 cycle = (ngx_cycle_t *) ngx_cycle; | |
481 continue; | |
482 } | |
483 | |
484 ngx_cycle = cycle; | |
485 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | |
486 | |
487 } else if (ngx_reopen) { | |
488 if (ngx_process == NGX_PROCESS_MASTER) { | |
489 signo = ngx_signal_value(NGX_REOPEN_SIGNAL); | |
490 ngx_reopen = 0; | |
491 | |
492 } else { /* NGX_PROCESS_SINGLE */ | |
493 ngx_reopen = 0; | |
494 } | |
495 | |
496 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | |
497 "reopening logs"); | |
498 ngx_reopen_files(cycle, ccf->user); | |
499 | |
500 } else if (ngx_change_binary) { | |
501 ngx_change_binary = 0; | |
502 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | |
503 "changing binary"); | |
504 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); | |
505 | |
506 } else if (ngx_noaccept) { | |
507 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | |
508 } | |
509 } | |
510 | |
511 if (signo) { | |
512 for (i = 0; i < ngx_last_process; i++) { | |
513 | |
514 if (ngx_processes[i].detached) { | |
515 continue; | |
516 } | |
517 | |
518 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
519 "kill (" PID_T_FMT ", %d)" , | |
520 ngx_processes[i].pid, signo); | |
521 | |
522 if (kill(ngx_processes[i].pid, signo) == -1) { | |
523 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
524 "kill(%d, %d) failed", | |
525 ngx_processes[i].pid, signo); | |
526 continue; | |
527 } | |
528 | |
529 if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) { | |
530 ngx_processes[i].exiting = 1; | |
531 } | |
532 } | |
533 | |
534 signo = 0; | |
535 } | |
536 | |
537 if (ngx_reopen || ngx_reconfigure || ngx_timer) { | |
538 break; | |
539 } | |
540 } | |
541 | |
542 if (ngx_reopen) { | |
543 ngx_reopen = 0; | |
544 | |
545 } else if (ngx_timer) { | |
546 ngx_timer = 0; | |
547 | |
548 } else if (ngx_noaccept) { | |
549 ngx_noaccept = 0; | |
550 ngx_reconfigure = 0; | |
551 | |
552 } else { | |
553 cycle = ngx_init_cycle(cycle); | |
554 if (cycle == NULL) { | |
555 cycle = (ngx_cycle_t *) ngx_cycle; | |
556 continue; | |
557 } | |
558 | |
559 ngx_cycle = cycle; | |
560 ngx_reconfigure = 0; | |
561 } | |
562 | |
563 break; | |
564 } | |
565 } | |
566 } | |
567 | |
568 | |
569 static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n) | |
570 { | 299 { |
571 struct itimerval itv; | 300 struct itimerval itv; |
572 | 301 |
573 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start worker processes"); | 302 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start worker processes"); |
574 | 303 |
575 while (n--) { | 304 while (n--) { |
576 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | 305 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, |
577 "worker process", NGX_PROCESS_RESPAWN); | 306 "worker process", type); |
578 } | 307 } |
579 | 308 |
580 /* | 309 /* |
581 * we have to limit the maximum life time of the worker processes | 310 * we have to limit the maximum life time of the worker processes |
582 * by 10 days because our millisecond event timer is limited | 311 * by 10 days because our millisecond event timer is limited |
589 itv.it_value.tv_usec = 0; | 318 itv.it_value.tv_usec = 0; |
590 | 319 |
591 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { | 320 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { |
592 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 321 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
593 "setitimer() failed"); | 322 "setitimer() failed"); |
323 } | |
324 } | |
325 | |
326 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo) | |
327 { | |
328 ngx_uint_t i; | |
329 | |
330 for (i = 0; i < ngx_last_process; i++) { | |
331 | |
332 if (ngx_processes[i].detached) { | |
333 continue; | |
334 } | |
335 | |
336 if (ngx_processes[i].just_respawn) { | |
337 ngx_processes[i].just_respawn = 0; | |
338 continue; | |
339 } | |
340 | |
341 if (ngx_processes[i].exiting | |
342 && signo == ngx_signal_value(NGX_SHUTDOWN_SIGNAL)) | |
343 { | |
344 continue; | |
345 } | |
346 | |
347 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
348 "kill (" PID_T_FMT ", %d)" , | |
349 ngx_processes[i].pid, signo); | |
350 | |
351 if (kill(ngx_processes[i].pid, signo) == -1) { | |
352 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
353 "kill(%d, %d) failed", | |
354 ngx_processes[i].pid, signo); | |
355 continue; | |
356 } | |
357 | |
358 if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) { | |
359 ngx_processes[i].exiting = 1; | |
360 } | |
594 } | 361 } |
595 } | 362 } |
596 | 363 |
597 | 364 |
598 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | 365 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) |