Removed debugging from ADB Rimo Import Broker

This commit is contained in:
Frank Schubert
2025-03-11 12:27:21 +01:00
parent 669f5cdc59
commit fae0bcfa5b
+23 -27
View File
@@ -5,10 +5,19 @@ if (PHP_SAPI !== 'cli') {
die("This program can only be run on the command line.\n"); die("This program can only be run on the command line.\n");
} }
posix_setrlimit(POSIX_RLIMIT_FSIZE, 1024*1024*1024, 1024*1024*1024); // Limit max filesize to 1 GB posix_setrlimit(POSIX_RLIMIT_FSIZE, 1024*1024*1024*5, 1024*1024*1024*5); // Limit max filesize to 5 GB
if(pidislocked()) {
_debug_log("ADB Rimo Import Broker läuft bereits (pidfile vorhanden)");
die("ADB Rimo Import Broker läuft bereits (pidfile vorhanden)");
}
if(!lockpid()) {
die("Error creating lock file!\n");
}
require("../../config/config.php"); require("../../config/config.php");
$debug_log = false;
/* /*
* Redirecting output so rlimit for filesize works * Redirecting output so rlimit for filesize works
@@ -82,15 +91,6 @@ pcntl_signal(SIGTERM, 'signalHandler');
$forkcount = 0; $forkcount = 0;
$childpids = []; $childpids = [];
if(pidislocked()) {
echo "ADB Rimo Import Broker läuft bereits (pidfile vorhanden)\n";
exit;
}
if(!lockpid()) {
$log->error(__FILE__.": Error creating lock file!");
die("Error creating lock file!\n");
}
$max_processes = 10; $max_processes = 10;
$all_pids = []; $all_pids = [];
@@ -146,14 +146,14 @@ while(1) {
foreach($processes as $key => $proc) { foreach($processes as $key => $proc) {
if($proc["pid"]) { if($proc["pid"]) {
// process is running already, nothing to do here // process is running already, nothing to do here
echo "[parent] ".$proc["cluster_id"]." pid exists (".$proc["pid"].")\n"; _debug_log("[parent] ".$proc["cluster_id"]." pid exists (".$proc["pid"].")");
continue; continue;
} }
$cluster_id = $proc["cluster_id"]; $cluster_id = $proc["cluster_id"];
if(isset($childpids[$cluster_id])) { if(isset($childpids[$cluster_id])) {
echo "[parent] job for ".$proc["cluster_id"]." exists\n"; _debug_log("[parent] job for ".$proc["cluster_id"]." exists");
//echo "cannot start new $taskname job, because another one is running already\n"; //echo "cannot start new $taskname job, because another one is running already\n";
continue; continue;
} }
@@ -167,13 +167,13 @@ while(1) {
} }
if(count($all_pids) >= $max_processes) { if(count($all_pids) >= $max_processes) {
echo "[parent] max processes reached. Currently ".count($all_pids)." running processes.\n"; _debug_log("[parent] max processes reached. Currently ".count($all_pids)." running processes.");
$fork_delay = 10; $fork_delay = 10;
sleep(1); sleep(1);
break; break;
} }
echo "[parent] forking for $cluster_id\n"; _debug_log("[parent] forking for $cluster_id");
$pid = pcntl_fork(); $pid = pcntl_fork();
$fork_delay = 10; $fork_delay = 10;
@@ -227,7 +227,7 @@ while(1) {
$status = false; $status = false;
$return_pid = pcntl_wait($status, WNOHANG); $return_pid = pcntl_wait($status, WNOHANG);
if($return_pid) { if($return_pid) {
echo "child $return_pid returned\n"; _debug_log("child $return_pid returned");
$pid_proc = $all_pids[$return_pid]; $pid_proc = $all_pids[$return_pid];
$pid_task = $pid_proc["cluster_id"]; $pid_task = $pid_proc["cluster_id"];
$childpids[$pid_task] = null; $childpids[$pid_task] = null;
@@ -321,18 +321,6 @@ function signalHandler($sig) {
exit; exit;
} }
function client_log($pid, $text, $severity = "notice") {
global $log;
global $is_daemon;
if($is_daemon) {
echo "[".date('Y-m-d H:i:s')."] [$pid] $text\n";
}
$log->$severity($text);
return true;
}
function pidislocked() { function pidislocked() {
$pidfile = __DIR__."/.adb-rimo-import-broker.lock"; $pidfile = __DIR__."/.adb-rimo-import-broker.lock";
if(file_exists($pidfile)) { if(file_exists($pidfile)) {
@@ -357,4 +345,12 @@ function unlockpid() {
return true; return true;
} }
return false; return false;
}
function _debug_log($text) {
global $debug_log;
if($debug_log) {
echo "$text\n";
}
} }