mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:40:16 +00:00
The function to check for maxload and the lockfile is centralized
This commit is contained in:
parent
ec9c9f0be7
commit
beb2346cfc
10 changed files with 66 additions and 172 deletions
37
boot.php
37
boot.php
|
@ -30,7 +30,7 @@ require_once('include/cache.php');
|
|||
require_once('library/Mobile_Detect/Mobile_Detect.php');
|
||||
require_once('include/features.php');
|
||||
require_once('include/identity.php');
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('update.php');
|
||||
require_once('include/dbstructure.php');
|
||||
|
||||
|
@ -1098,6 +1098,41 @@ class App {
|
|||
return($this->is_friendica_app);
|
||||
}
|
||||
|
||||
function maxload_reached() {
|
||||
|
||||
$maxsysload = intval(get_config('system', 'maxloadavg'));
|
||||
if ($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if ($load) {
|
||||
if (intval($load) > $maxsysload) {
|
||||
logger('system: load '.$load.' too high.');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_already_running($task, $taskname, $timeout = 540) {
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, $taskname);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > $timeout) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
if ($task != "")
|
||||
proc_run('php', $task);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,6 @@ function cron_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
|
||||
load_config('config');
|
||||
|
@ -42,32 +41,10 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load '.$load.' too high. cron deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cron');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cron: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("cron: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cron.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('include/cron.php', 'cron', 540))
|
||||
return;
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cron');
|
||||
|
|
|
@ -19,39 +19,16 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cronhooks');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cronhooks: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("cronhooks: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cronhooks.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('include/cronhooks.php', 'cronhooks', 1140))
|
||||
return;
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cronhook');
|
||||
|
|
|
@ -57,17 +57,8 @@ function delivery_run(&$argv, &$argc){
|
|||
continue;
|
||||
}
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// It's ours to deliver. Remove it from the queue.
|
||||
|
||||
|
|
|
@ -20,25 +20,14 @@ function discover_poco_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load '.$load.' too high. discover_poco deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
if(($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
$search = urldecode($argv[2]);
|
||||
|
@ -54,23 +43,9 @@ function discover_poco_run(&$argv, &$argc){
|
|||
die("Unknown or missing parameter ".$argv[1]."\n");
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("discover_poco: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("discover_poco: killed stale process");
|
||||
// Calling a new instance
|
||||
if ($mode == 0)
|
||||
proc_run('php','include/discover_poco.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('include/discover_poco.php', 'discover_poco'.$mode.urlencode($search), 1140))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ function onepoll_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
load_config('config');
|
||||
|
@ -61,20 +60,9 @@ function onepoll_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("onepoll: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('', 'onepoll'.$contact_id, 540))
|
||||
return;
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
|
|
|
@ -29,17 +29,8 @@ function poller_run(&$argv, &$argc){
|
|||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// Checking the number of workers
|
||||
if (poller_too_much_workers(1)) {
|
||||
|
|
|
@ -74,28 +74,14 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
};
|
||||
|
||||
require_once('include/items.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'pubsubpublish');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/pubsubpublish.php");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running("include/pubsubpublish.php", 'pubsubpublish', 540))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -22,29 +22,15 @@ function queue_run(&$argv, &$argc){
|
|||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'queue');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("queue: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("queue: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/queue.php");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('include/queue.php', 'queue', 540))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/Scrape.php');
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
|
@ -38,20 +37,9 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("update_gcontact: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('', 'update_gcontact'.$contact_id, 540))
|
||||
return;
|
||||
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
|
||||
|
||||
|
|
Loading…
Reference in a new issue