* This script was taken from http://php.net/manual/en/function.pcntl-fork.php
*/
-use Friendica\App;
use Friendica\Core\Config;
+use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\Factory;
// Get options
-$shortopts = '';
-$shortopts .= 'f';
-$longopts = [ 'foreground' ];
+$shortopts = 'f';
+$longopts = ['foreground'];
$options = getopt($shortopts, $longopts);
// Ensure that daemon.php is executed from the base path of the installation
chdir($directory);
}
-require_once "boot.php";
-require_once "include/dba.php";
+require dirname(__DIR__) . '/vendor/autoload.php';
-$a = new App(dirname(__DIR__));
+$a = Factory\DependencyFactory::setUp('daemon', dirname(__DIR__));
-if ($a->isInstallMode()) {
+if ($a->getMode()->isInstall()) {
die("Friendica isn't properly installed yet.\n");
}
Config::load();
if (empty(Config::get('system', 'pidfile'))) {
- die('Please set system.pidfile in config/local.ini.php. For example:'."\n".
- '[system]'."\n".
- 'pidfile = /path/to/daemon.pid'."\n");
+ die(<<<TXT
+Please set system.pidfile in config/local.config.php. For example:
+
+ 'system' => [
+ 'pidfile' => '/path/to/daemon.pid',
+ ],
+TXT
+ );
}
$pidfile = Config::get('system', 'pidfile');
unlink($pidfile);
- logger("Worker daemon process $pid was killed.", LOGGER_DEBUG);
+ Logger::notice("Worker daemon process was killed", ["pid" => $pid]);
Config::set('system', 'worker_daemon_mode', false);
die("Worker daemon process $pid was killed.\n");
die("Daemon process $pid is already running.\n");
}
-logger('Starting worker daemon.', LOGGER_DEBUG);
+Logger::notice('Starting worker daemon.', ["pid" => $pid]);
if (!$foreground) {
echo "Starting worker daemon.\n";
file_put_contents($pidfile, $pid);
// We lose the database connection upon forking
- $a->loadDatabase();
+ /// @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);
}
Config::set('system', 'worker_daemon_mode', true);
// Now running as a daemon.
while (true) {
if (!$do_cron && ($last_cron + $wait_interval) < time()) {
- logger('Forcing cron worker call.', LOGGER_DEBUG);
+ Logger::info('Forcing cron worker call.', ["pid" => $pid]);
$do_cron = true;
}
$last_cron = time();
}
- logger("Sleeping", LOGGER_DEBUG);
+ Logger::info("Sleeping", ["pid" => $pid]);
$start = time();
do {
$seconds = (time() - $start);
if ($timeout) {
$do_cron = true;
- logger("Woke up after $wait_interval seconds.", LOGGER_DEBUG);
+ Logger::info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]);
} else {
$do_cron = false;
- logger("Worker jobs are calling to be forked.", LOGGER_DEBUG);
+ Logger::info("Worker jobs are calling to be forked.", ["pid" => $pid]);
}
}