]> git.mxchange.org Git - friendica.git/blobdiff - bin/daemon.php
Move is_a_date_arg to DateTimeFormat::isYearMonth
[friendica.git] / bin / daemon.php
index 5c014a92702429d58af4dfab1ac163597d34b95d..948829c1bf8ae02815af420267ce3c1f3f02e7d3 100755 (executable)
@@ -7,12 +7,12 @@
  * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
  */
 
-use Friendica\App;
+use Dice\Dice;
 use Friendica\Core\Config;
+use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Factory;
-use Friendica\Util\BasePath;
+use Psr\Log\LoggerInterface;
 
 // Get options
 $shortopts = 'f';
@@ -33,12 +33,11 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
 
 require dirname(__DIR__) . '/vendor/autoload.php';
 
-$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
-$configLoader = new Config\ConfigCacheLoader($basedir);
-$config = Factory\ConfigFactory::createCache($configLoader);
-$logger = Factory\LoggerFactory::create('daemon', $config);
+$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
+$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]);
 
-$a = new App($config, $logger);
+\Friendica\BaseObject::setDependencyInjection($dice);
+$a = \Friendica\BaseObject::getApp();
 
 if ($a->getMode()->isInstall()) {
        die("Friendica isn't properly installed yet.\n");
@@ -108,7 +107,7 @@ 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);
        die("Worker daemon process $pid was killed.\n");
@@ -118,7 +117,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";
@@ -150,7 +149,7 @@ if (!$foreground) {
        file_put_contents($pidfile, $pid);
 
        // We lose the database connection upon forking
-       $a->loadDatabase();
+       DBA::reconnect();
 }
 
 Config::set('system', 'worker_daemon_mode', true);
@@ -166,7 +165,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;
        }
 
@@ -180,7 +179,7 @@ while (true) {
                $last_cron = time();
        }
 
-       $logger->info("Sleeping", ["pid" => $pid]);
+       Logger::info("Sleeping", ["pid" => $pid]);
        $start = time();
        do {
                $seconds = (time() - $start);
@@ -197,10 +196,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]);
        }
 }