X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=bin%2Fdaemon.php;h=c2ce05c8e04b346aededf84fcb4fa90e8e51195e;hb=a74c547af470947c3420157cba237c4951da58f4;hp=f2970a5180261163227113c4dd0811f94ff1df34;hpb=80f1feabe5ecf9b09b76627ba4b114ae10ddcaf6;p=friendica.git diff --git a/bin/daemon.php b/bin/daemon.php index f2970a5180..c2ce05c8e0 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -1,19 +1,34 @@ #!/usr/bin/env php . + * + * Run the worker from a daemon. * * This script was taken from http://php.net/manual/en/function.pcntl-fork.php */ -use Friendica\App; -use Friendica\Core\Config; -use Friendica\Core\Config\Cache; +use Dice\Dice; +use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Factory; -use Friendica\Util\BasePath; +use Friendica\DI; +use Psr\Log\LoggerInterface; // Get options $shortopts = 'f'; @@ -34,25 +49,19 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; -$basedir = BasePath::create(dirname(__DIR__), $_SERVER); -$configLoader = new Cache\ConfigCacheLoader($basedir); -$configCache = Factory\ConfigFactory::createCache($configLoader); -Factory\DBFactory::init($configCache, $_SERVER); -$config = Factory\ConfigFactory::createConfig($configCache); -// needed to call PConfig::init() -Factory\ConfigFactory::createPConfig($configCache); -$logger = Factory\LoggerFactory::create('daemon', $config); -$profiler = Factory\ProfilerFactory::create($logger, $config); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); -$a = new App($config, $logger, $profiler); +DI::init($dice); +$a = DI::app(); -if ($a->getMode()->isInstall()) { +if (DI::mode()->isInstall()) { die("Friendica isn't properly installed yet.\n"); } -Config::load(); +DI::config()->load(); -if (empty(Config::get('system', 'pidfile'))) { +if (empty(DI::config()->get('system', 'pidfile'))) { die(<<get('system', 'pidfile'); if (in_array("start", $_SERVER["argv"])) { $mode = "start"; @@ -94,7 +103,7 @@ if (is_readable($pidfile)) { } if (empty($pid) && in_array($mode, ["stop", "status"])) { - Config::set('system', 'worker_daemon_mode', false); + DI::config()->set('system', 'worker_daemon_mode', false); die("Pidfile wasn't found. Is the daemon running?\n"); } @@ -105,7 +114,7 @@ if ($mode == "status") { unlink($pidfile); - Config::set('system', 'worker_daemon_mode', false); + DI::config()->set('system', 'worker_daemon_mode', false); die("Daemon process $pid isn't running.\n"); } @@ -114,9 +123,9 @@ if ($mode == "stop") { unlink($pidfile); - $logger->notice("Worker daemon process was killed", ["pid" => $pid]); + Logger::notice("Worker daemon process was killed", ["pid" => $pid]); - Config::set('system', 'worker_daemon_mode', false); + DI::config()->set('system', 'worker_daemon_mode', false); die("Worker daemon process $pid was killed.\n"); } @@ -124,7 +133,7 @@ if (!empty($pid) && posix_kill($pid, 0)) { die("Daemon process $pid is already running.\n"); } -$logger->notice('Starting worker daemon.', ["pid" => $pid]); +Logger::notice('Starting worker daemon.', ["pid" => $pid]); if (!$foreground) { echo "Starting worker daemon.\n"; @@ -156,15 +165,15 @@ if (!$foreground) { file_put_contents($pidfile, $pid); // We lose the database connection upon forking - Factory\DBFactory::init($configCache, $_SERVER); + DBA::reconnect(); } -Config::set('system', 'worker_daemon_mode', true); +DI::config()->set('system', 'worker_daemon_mode', true); // Just to be sure that this script really runs endlessly set_time_limit(0); -$wait_interval = intval(Config::get('system', 'cron_interval', 5)) * 60; +$wait_interval = intval(DI::config()->get('system', 'cron_interval', 5)) * 60; $do_cron = true; $last_cron = 0; @@ -172,7 +181,7 @@ $last_cron = 0; // Now running as a daemon. while (true) { if (!$do_cron && ($last_cron + $wait_interval) < time()) { - $logger->info('Forcing cron worker call.', ["pid" => $pid]); + Logger::info('Forcing cron worker call.', ["pid" => $pid]); $do_cron = true; } @@ -186,7 +195,7 @@ while (true) { $last_cron = time(); } - $logger->info("Sleeping", ["pid" => $pid]); + Logger::info("Sleeping", ["pid" => $pid]); $start = time(); do { $seconds = (time() - $start); @@ -203,10 +212,10 @@ while (true) { if ($timeout) { $do_cron = true; - $logger->info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]); + Logger::info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]); } else { $do_cron = false; - $logger->info("Worker jobs are calling to be forked.", ["pid" => $pid]); + Logger::info("Worker jobs are calling to be forked.", ["pid" => $pid]); } }