X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=bin%2Fdaemon.php;h=c2ce05c8e04b346aededf84fcb4fa90e8e51195e;hb=04c95a5045136cb18d09f0ae6f9cb46975dace13;hp=298cfa2534ad1221ddbf1cf7561de89830b354e2;hpb=c1896eee34778ae022481af56f634bd6374544d2;p=friendica.git diff --git a/bin/daemon.php b/bin/daemon.php index 298cfa2534..c2ce05c8e0 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -1,17 +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\Core\Config; +use Dice\Dice; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Factory; +use Friendica\DI; +use Psr\Log\LoggerInterface; // Get options $shortopts = 'f'; @@ -32,15 +49,19 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; -$a = Factory\DependencyFactory::setUp('daemon', dirname(__DIR__)); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); + +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"; @@ -82,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"); } @@ -93,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"); } @@ -104,7 +125,7 @@ if ($mode == "stop") { 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"); } @@ -144,17 +165,15 @@ if (!$foreground) { file_put_contents($pidfile, $pid); // We lose the database connection upon forking - /// @todo refactoring during https://github.com/friendica/friendica/issues/6720 - $basePath = \Friendica\Util\BasePath::create(dirname(__DIR__), $_SERVER); - Factory\DBFactory::init($basePath, $a->getConfigCache(), $a->getProfiler(), $_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;