From 0e77c7fd324b99006b01c248a0e3295d2c07cec9 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Mar 2016 01:05:31 +0300 Subject: Make web server to terminate if module fail to initialize --- web/apache/service.txx | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'web') diff --git a/web/apache/service.txx b/web/apache/service.txx index 961c19b..1d0693a 100644 --- a/web/apache/service.txx +++ b/web/apache/service.txx @@ -2,11 +2,10 @@ // copyright : Copyright (c) 2014-2016 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include // getppid() -#include // kill(), SIGTERM - +#include // APEXIT_CHILDSICK #include // APLOG_* +#include // exit() #include // move() #include @@ -65,16 +64,23 @@ namespace web { l.write (nullptr, 0, func_name.c_str (), APLOG_EMERG, e.what ()); - // Terminate the root apache process. Indeed we can only try to - // terminate the process, and most likely will fail in a production - // environment, where the apache root process usually runs under root, - // and worker processes run under some other user. This is why the - // implementation should consider the possibility of not being - // initialized at the time of HTTP request processing. In such a case - // it should respond with an internal server error (500 HTTP status), - // reporting misconfiguration. + // Terminate the worker apache process. APEXIT_CHILDSICK indicates to + // the root process that the worker have exited due to a resource + // shortage. In this case the root process limits the rate of forking + // until situation is resolved. + // + // If the root process fails to create any worker process on startup, + // the behaviour depends on the Multi-Processing Module enabled. For + // mpm_worker_module and mpm_event_module the root process terminates. + // For mpm_prefork_module it keeps trying to create the worker process + // at one-second intervals. + // + // If the root process loses all it's workers while running (for + // example due to the MaxRequestsPerChild directive), and fails to + // create any new ones, it keeps trying to create the worker process + // at one-second intervals. // - kill (getppid (), SIGTERM); + std::exit (APEXIT_CHILDSICK); } catch (...) { @@ -84,9 +90,9 @@ namespace web APLOG_EMERG, "unknown error"); - // Terminate the root apache process. + // Terminate the worker apache process. // - kill (getppid (), SIGTERM); + std::exit (APEXIT_CHILDSICK); } } -- cgit v1.1