diff options
author | Andrew Dolgov <[email protected]> | 2021-02-24 21:56:52 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-24 21:56:52 +0300 |
commit | 93940d2a9f80d9e1dac49b5eb7db23230d31c5f6 (patch) | |
tree | 71016661f6017918d0934eb462bd9552018d557a /update_daemon2.php | |
parent | 8b022c2bfb356d7dddaf334bc931d6dec77086fb (diff) | |
parent | 1adacd057230aea4ede29dab510385bf01cf99a3 (diff) |
Merge branch 'master' of git.fakecake.org:fox/tt-rss into weblate-integration
Diffstat (limited to 'update_daemon2.php')
-rwxr-xr-x | update_daemon2.php | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/update_daemon2.php b/update_daemon2.php index 61cc85617..b75f06ae5 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -1,26 +1,16 @@ #!/usr/bin/env php <?php - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . + set_include_path(__DIR__ ."/include" . PATH_SEPARATOR . get_include_path()); declare(ticks = 1); - chdir(dirname(__FILE__)); + chdir(__DIR__); define('DISABLE_SESSIONS', true); require_once "autoload.php"; require_once "functions.php"; - require_once "config.php"; - - // defaults - define_default('PURGE_INTERVAL', 3600); // seconds - define_default('MAX_CHILD_RUNTIME', 1800); // seconds - define_default('MAX_JOBS', 2); - define_default('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL); // seconds - require_once "sanity_check.php"; - require_once "db.php"; - require_once "db-prefs.php"; if (!function_exists('pcntl_fork')) { die("error: This script requires PHP compiled with PCNTL module.\n"); @@ -79,7 +69,7 @@ foreach (array_keys($ctimes) as $pid) { $started = $ctimes[$pid]; - if (time() - $started > MAX_CHILD_RUNTIME) { + if (time() - $started > Config::get(Config::DAEMON_MAX_CHILD_RUNTIME)) { Debug::log("Child process with PID $pid seems to be stuck, aborting..."); posix_kill($pid, SIGKILL); } @@ -99,9 +89,9 @@ function shutdown($caller_pid) { if ($caller_pid == posix_getpid()) { - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock")) { Debug::log("Removing lockfile (master)..."); - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock"); } } } @@ -109,9 +99,9 @@ function task_shutdown() { $pid = posix_getpid(); - if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock")) { Debug::log("Removing task lockfile for PID $pid..."); - unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock"); } } @@ -144,9 +134,9 @@ print " --log FILE - log messages to FILE\n"; print " --log-level N - log verbosity level\n"; print " --tasks N - amount of update tasks to spawn\n"; - print " default: " . MAX_JOBS . "\n"; + print " default: " . Config::get(Config::DAEMON_MAX_JOBS) . "\n"; print " --interval N - task spawn interval\n"; - print " default: " . SPAWN_INTERVAL . " seconds.\n"; + print " default: " . Config::get(Config::DAEMON_SLEEP_INTERVAL) . " seconds.\n"; print " --quiet - don't output messages to stdout\n"; return; } @@ -171,14 +161,14 @@ Debug::log("Set to spawn " . $options["tasks"] . " children."); $max_jobs = $options["tasks"]; } else { - $max_jobs = MAX_JOBS; + $max_jobs = Config::get(Config::DAEMON_MAX_JOBS); } if (isset($options["interval"])) { Debug::log("Spawn interval: " . $options["interval"] . " seconds."); $spawn_interval = $options["interval"]; } else { - $spawn_interval = SPAWN_INTERVAL; + $spawn_interval = Config::get(Config::DAEMON_SLEEP_INTERVAL); } // let's enforce a minimum spawn interval as to not forkbomb the host @@ -250,7 +240,7 @@ $my_pid = posix_getpid(); - passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); + passthru(Config::get(Config::PHP_EXECUTABLE) . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); sleep(1); |