From ae172a9cec404ef9a0e9f16aafea97dea64d33ab Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 15 Mar 2015 07:45:50 +0100 Subject: [PATCH] If the load is too high, now not only the poller but also the page delivery will stop. --- include/cronhooks.php | 2 +- include/delivery.php | 2 +- include/poller.php | 2 +- index.php | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/cronhooks.php b/include/cronhooks.php index 3a09da48c..26cab3cf9 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -30,7 +30,7 @@ function cronhooks_run(&$argv, &$argc){ if(function_exists('sys_getloadavg')) { $load = sys_getloadavg(); if(intval($load[0]) > $maxsysload) { - logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); + logger('system: load ' . $load[0] . ' too high. Cronhooks deferred to next scheduled run.'); return; } } diff --git a/include/delivery.php b/include/delivery.php index 1def8ad2c..a913e1317 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -60,7 +60,7 @@ function delivery_run(&$argv, &$argc){ if(function_exists('sys_getloadavg')) { $load = sys_getloadavg(); if(intval($load[0]) > $maxsysload) { - logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.'); + logger('system: load ' . $load[0] . ' too high. Delivery deferred to next queue run.'); return; } } diff --git a/include/poller.php b/include/poller.php index cef11a744..933624ecb 100644 --- a/include/poller.php +++ b/include/poller.php @@ -46,7 +46,7 @@ function poller_run(&$argv, &$argc){ if(function_exists('sys_getloadavg')) { $load = sys_getloadavg(); if(intval($load[0]) > $maxsysload) { - logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); + logger('system: load ' . $load[0] . ' too high. Poller deferred to next scheduled run.'); return; } } diff --git a/index.php b/index.php index 295db01da..949ccd532 100644 --- a/index.php +++ b/index.php @@ -53,6 +53,20 @@ if(!$install) { load_config('config'); load_config('system'); + $maxsysload = intval(get_config('system','maxloadavg')); + if($maxsysload < 1) + $maxsysload = 50; + if(function_exists('sys_getloadavg')) { + $load = sys_getloadavg(); + if(intval($load[0]) > $maxsysload) { + logger('system: load ' . $load[0] . ' too high. Service Temporarily Unavailable.'); + header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable'); + header('Retry-After: 300'); + die("System is currently unavailable. Please try again later"); + } + } + + if (get_config('system','force_ssl') AND ($a->get_scheme() == "http") AND (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND (substr($a->get_baseurl(), 0, 8) == "https://")) {