aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-03-18 01:05:31 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-03-18 01:05:31 +0300
commit0e77c7fd324b99006b01c248a0e3295d2c07cec9 (patch)
tree06ad0555acaadcb72130b0465cc0b49032d27f2e
parent0b6b57f9acaa2ec648bf582ff67851331f8e6eef (diff)
Make web server to terminate if module fail to initialize
-rw-r--r--brep/module9
-rw-r--r--brep/module.cxx8
-rw-r--r--web/apache/service.txx34
3 files changed, 28 insertions, 23 deletions
diff --git a/brep/module b/brep/module
index 3796399..7e5763a 100644
--- a/brep/module
+++ b/brep/module
@@ -141,7 +141,8 @@ namespace brep
virtual void
init (cli::scanner&) = 0;
- // Can be overriden by custom request dispatcher to initialize sub-modules.
+ // Can be overriden by custom request dispatcher to initialize
+ // sub-modules.
//
virtual void
init (const name_values&);
@@ -158,9 +159,9 @@ namespace brep
// web::module interface.
//
public:
- // Custom request dispatcher can aggregate its own option descriptions with
- // sub-modules option descriptions. In this case it should still call the
- // base implementation in order to include the brep::module's options.
+ // Custom request dispatcher can aggregate its own option descriptions
+ // with sub-modules option descriptions. In this case it should still call
+ // the base implementation in order to include the brep::module's options.
//
virtual option_descriptions
options ();
diff --git a/brep/module.cxx b/brep/module.cxx
index 40acad9..68969eb 100644
--- a/brep/module.cxx
+++ b/brep/module.cxx
@@ -30,11 +30,9 @@ namespace brep
try
{
- if (!initialized_)
- {
- MODULE_DIAG;
- fail << "not initialized, presumably due to misconfiguration";
- }
+ // Web server should terminate if initialization failed.
+ //
+ assert (initialized_);
return handle (rq, rs);
}
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 <unistd.h> // getppid()
-#include <signal.h> // kill(), SIGTERM
-
+#include <httpd.h> // APEXIT_CHILDSICK
#include <http_log.h> // APLOG_*
+#include <cstdlib> // exit()
#include <utility> // move()
#include <exception>
@@ -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);
}
}