From 64e66acb01a07d4853b5b1a87ebdc66638dc4f79 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 1 Jan 2025 23:38:19 +0100 Subject: [PATCH 01/12] Add system daemon class --- src/Console/Daemon.php | 232 ++++++++++++++++++----------------------- src/System/Daemon.php | 153 +++++++++++++++++++++++++++ 2 files changed, 252 insertions(+), 133 deletions(-) create mode 100644 src/System/Daemon.php diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index e6b19149fd..e1810bb9cb 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -17,6 +17,7 @@ use Friendica\Core\System; use Friendica\Core\Update; use Friendica\Core\Worker; use Friendica\Database\Database; +use Friendica\System\Daemon as SysDaemon; use Friendica\Util\BasePath; use Friendica\Util\DateTimeFormat; use Psr\Log\LoggerInterface; @@ -34,6 +35,7 @@ final class Daemon extends Console private System $system; private LoggerInterface $logger; private Database $dba; + private SysDaemon $daemon; /** * @param Mode $mode @@ -43,9 +45,10 @@ final class Daemon extends Console * @param System $system * @param LoggerInterface $logger * @param Database $dba + * @param SysDaemon $daemon * @param array|null $argv */ - public function __construct(Mode $mode, IManageConfigValues $config, IManageKeyValuePairs $keyValue, BasePath $basePath, System $system, LoggerInterface $logger, Database $dba, array $argv = null) + public function __construct(Mode $mode, IManageConfigValues $config, IManageKeyValuePairs $keyValue, BasePath $basePath, System $system, LoggerInterface $logger, Database $dba, SysDaemon $daemon, array $argv = null) { parent::__construct($argv); @@ -56,6 +59,7 @@ final class Daemon extends Console $this->system = $system; $this->logger = $logger; $this->dba = $dba; + $this->daemon = $daemon; } protected function getHelp(): string @@ -63,7 +67,9 @@ final class Daemon extends Console return << [ 'pidfile' => '/path/to/daemon.pid', ], - TXT); + TXT + ); } $pidfile = $this->config->get('system', 'pidfile'); $daemonMode = $this->getArgument(0); - $foreground = $this->getOption(['f', 'foreground']); + $foreground = $this->getOption(['f', 'foreground']) ?? false; if (empty($daemonMode)) { throw new RuntimeException("Please use either 'start', 'stop' or 'status'"); } - $pid = null; - if (is_readable($pidfile)) { - $pid = intval(file_get_contents($pidfile)); - } - - if (empty($pid) && in_array($daemonMode, ['stop', 'status'])) { - $this->keyValue->set('worker_daemon_mode', false); - throw new RuntimeException("Pidfile wasn't found. Is the daemon running?"); - } + $this->daemon->init($pidfile); if ($daemonMode == 'status') { - if (posix_kill($pid, 0)) { - $this->out("Daemon process $pid is running"); - return 0; + if ($this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s is running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + } else { + $this->out(sprintf("Daemon process %s isn't running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); } - - unlink($pidfile); - - $this->keyValue->set('worker_daemon_mode', false); - $this->out("Daemon process $pid isn't running."); return 0; } if ($daemonMode == 'stop') { - posix_kill($pid, SIGTERM); - unlink($pidfile); + if (!$this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s isn't running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 0; + } - $this->logger->notice('Worker daemon process was killed', ['pid' => $pid]); + if ($this->daemon->stop()) { + $this->keyValue->set('worker_daemon_mode', false); + $this->out(sprintf("Daemon process %s was killed (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 0; + } + + return 1; + } + + if ($this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s is already running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 1; + } + + if ($daemonMode == "start") { + $this->out("Starting worker daemon"); + + $this->daemon->start(function () { + $wait_interval = intval($this->config->get('system', 'cron_interval', 5)) * 60; + + $do_cron = true; + $last_cron = 0; + + $path = $this->basePath->getPath(); + + // Now running as a daemon. + while (true) { + // Check the database structure and possibly fixes it + Update::check($path, true); + + if (!$do_cron && ($last_cron + $wait_interval) < time()) { + $this->logger->info('Forcing cron worker call.', ['pid' => $this->daemon->getPid()]); + $do_cron = true; + } + + if ($do_cron || (!$this->system->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) { + Worker::spawnWorker($do_cron); + } else { + $this->logger->info('Cool down for 5 seconds', ['pid' => $this->daemon->getPid()]); + sleep(5); + } + + if ($do_cron) { + // We force a reconnect of the database connection. + // This is done to ensure that the connection don't get lost over time. + $this->dba->reconnect(); + + $last_cron = time(); + } + + $start = time(); + $this->logger->info('Sleeping', ['pid' => $this->daemon->getPid(), 'until' => gmdate(DateTimeFormat::MYSQL, $start + $wait_interval)]); + + do { + $seconds = (time() - $start); + + // logarithmic wait time calculation. + // Background: After jobs had been started, they often fork many workers. + // To not waste too much time, the sleep period increases. + $arg = (($seconds + 1) / ($wait_interval / 9)) + 1; + $sleep = min(1000000, round(log10($arg) * 1000000, 0)); + + $this->daemon->sleep((int)$sleep); + + $timeout = ($seconds >= $wait_interval); + } while (!$timeout && !Worker\IPC::JobsExists()); + + if ($timeout) { + $do_cron = true; + $this->logger->info('Woke up after $wait_interval seconds.', ['pid' => $this->daemon->getPid(), 'sleep' => $wait_interval]); + } else { + $do_cron = false; + $this->logger->info('Worker jobs are calling to be forked.', ['pid' => $this->daemon->getPid()]); + } + } + }, $foreground); - $this->keyValue->set('worker_daemon_mode', false); - $this->out("Daemon process $pid was killed."); return 0; } - $this->logger->notice('Starting worker daemon', ['pid' => $pid]); - - if (!$foreground) { - $this->out("Starting worker daemon"); - $this->dba->disconnect(); - - // Fork a daemon process - $pid = pcntl_fork(); - if ($pid == -1) { - $this->logger->warning('Could not fork daemon'); - throw new RuntimeException("Daemon couldn't be forked"); - } elseif ($pid) { - // The parent process continues here - if (!file_put_contents($pidfile, $pid)) { - posix_kill($pid, SIGTERM); - $this->logger->warning('Could not store pid file'); - throw new RuntimeException("Pid file wasn't written"); - } - $this->out("Child process started with pid $pid"); - $this->logger->notice('Child process started', ['pid' => $pid]); - return 0; - } - - // We now are in the child process - register_shutdown_function(function () { - posix_kill(posix_getpid(), SIGTERM); - posix_kill(posix_getpid(), SIGHUP); - }); - - // Make the child the main process, detach it from the terminal - if (posix_setsid() < 0) { - return 0; - } - - // Closing all existing connections with the outside - fclose(STDIN); - - // And now connect the database again - $this->dba->connect(); - } - - $this->keyValue->set('worker_daemon_mode', true); - - // Just to be sure that this script really runs endlessly - set_time_limit(0); - - $wait_interval = intval($this->config->get('system', 'cron_interval', 5)) * 60; - - $do_cron = true; - $last_cron = 0; - - $path = $this->basePath->getPath(); - - // Now running as a daemon. - while (true) { - // Check the database structure and possibly fixes it - Update::check($path, true); - - if (!$do_cron && ($last_cron + $wait_interval) < time()) { - $this->logger->info('Forcing cron worker call.', ['pid' => $pid]); - $do_cron = true; - } - - if ($do_cron || (!$this->system->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) { - Worker::spawnWorker($do_cron); - } else { - $this->logger->info('Cool down for 5 seconds', ['pid' => $pid]); - sleep(5); - } - - if ($do_cron) { - // We force a reconnect of the database connection. - // This is done to ensure that the connection don't get lost over time. - $this->dba->reconnect(); - - $last_cron = time(); - } - - $start = time(); - $this->logger->info('Sleeping', ['pid' => $pid, 'until' => gmdate(DateTimeFormat::MYSQL, $start + $wait_interval)]); - - do { - $seconds = (time() - $start); - - // logarithmic wait time calculation. - // Background: After jobs had been started, they often fork many workers. - // To not waste too much time, the sleep period increases. - $arg = (($seconds + 1) / ($wait_interval / 9)) + 1; - $sleep = min(1000000, round(log10($arg) * 1000000, 0)); - usleep((int)$sleep); - - $pid = pcntl_waitpid(-1, $status, WNOHANG); - if ($pid > 0) { - $this->logger->info('Children quit via pcntl_waitpid', ['pid' => $pid, 'status' => $status]); - } - - $timeout = ($seconds >= $wait_interval); - } while (!$timeout && !Worker\IPC::JobsExists()); - - if ($timeout) { - $do_cron = true; - $this->logger->info('Woke up after $wait_interval seconds.', ['pid' => $pid, 'sleep' => $wait_interval]); - } else { - $do_cron = false; - $this->logger->info('Worker jobs are calling to be forked.', ['pid' => $pid]); - } - } + $this->err('Invalid command'); + $this->out($this->getHelp()); + return 1; } } diff --git a/src/System/Daemon.php b/src/System/Daemon.php new file mode 100644 index 0000000000..61c281bd66 --- /dev/null +++ b/src/System/Daemon.php @@ -0,0 +1,153 @@ +pid; + } + + public function getPidfile(): ?string + { + return $this->pidfile; + } + + public function __construct(LoggerInterface $logger, Database $dba) + { + $this->logger = $logger; + $this->dba = $dba; + } + + public function init($pidfile = null): void + { + if (!empty($pidfile)) { + $this->pid = null; + $this->pidfile = $pidfile; + } + + if (!empty($this->pid)) { + return; + } + + if (is_readable($this->pidfile)) { + $this->pid = intval(file_get_contents($this->pidfile)); + } + } + + public function start(callable $daemonLogic, bool $foreground = false): bool + { + $this->init(); + + if (!empty($this->pid)) { + $this->logger->notice('process is already running', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + return false; + } + + $this->logger->notice('starting daemon', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + + if (!$foreground) { + $this->dba->disconnect(); + + // fork a daemon process + $this->pid = pcntl_fork(); + if ($this->pid < 0) { + $this->logger->warning('Could not fork daemon'); + return false; + } elseif ($this->pid) { + // The parent process continues here + if (!file_put_contents($this->pidfile, $this->pid)) { + $this->logger->warning('Could not store pid file', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + posix_kill($this->pid, SIGTERM); + return false; + } + $this->logger->notice('Child process started', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + return true; + } + + // We now are in the child process + register_shutdown_function(function (): void { + posix_kill(posix_getpid(), SIGTERM); + posix_kill(posix_getpid(), SIGHUP); + }); + + // Make the child the main process, detach it from the terminal + if (posix_setsid() < 0) { + return true; + } + + // Closing all existing connections with the outside + fclose(STDIN); + + // And now connect the database again + $this->dba->connect(); + } + + // Just to be sure that this script really runs endlessly + set_time_limit(0); + + $daemonLogic(); + + return true; + } + + public function isRunning(): bool + { + $this->init(); + + if (empty($this->pid)) { + $this->logger->notice("Pid wasn't found"); + + if (is_readable($this->pidfile)) { + unlink($this->pidfile); + $this->logger->notice("Pidfile removed", ['pidfile' => $this->pidfile]); + } + return false; + } + + if (posix_kill($this->pid, 0)) { + $this->logger->notice("daemon process is running"); + return true; + } else { + unlink($this->pidfile); + $this->logger->notice("daemon process isn't running"); + return false; + } + } + + public function stop(): bool + { + $this->init(); + + if (empty($this->pid)) { + $this->logger->notice("Pidfile wasn't found", ['pidfile' => $this->pidfile]); + return true; + } + + posix_kill($this->pid, SIGTERM); + unlink($this->pidfile); + + $this->logger->notice('daemon process was killed', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + + return true; + } + + public function sleep(int $duration) + { + usleep($duration); + + $this->pid = pcntl_waitpid(-1, $status, WNOHANG); + if ($this->pid > 0) { + $this->logger->info('Children quit via pcntl_waitpid', ['pid' => $this->pid, 'status' => $status]); + } + } +} From 3d2524532fe744e79e3c747c493affa2cb496ad5 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 1 Jan 2025 23:52:48 +0100 Subject: [PATCH 02/12] Add Jetstream daemon to console --- bin/jetstream.php | 5 +- src/App.php | 153 +------------------------ src/Console/JetstreamDaemon.php | 154 ++++++++++++++++++++++++++ src/Core/Console.php | 2 + src/Protocol/ATProtocol/Jetstream.php | 11 +- 5 files changed, 167 insertions(+), 158 deletions(-) create mode 100644 src/Console/JetstreamDaemon.php diff --git a/bin/jetstream.php b/bin/jetstream.php index b2df4d38dc..c696d044b9 100755 --- a/bin/jetstream.php +++ b/bin/jetstream.php @@ -24,4 +24,7 @@ $dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies. $app = \Friendica\App::fromDice($dice); -$app->processJetstream(); +$argv = $_SERVER['argv'] ?? []; +array_splice($argv, 1, 0, "jetstream"); + +$app->processConsole($argv); diff --git a/src/App.php b/src/App.php index a233e079f1..57b32e082b 100644 --- a/src/App.php +++ b/src/App.php @@ -217,161 +217,10 @@ class App $this->registerTemplateEngine(); - (new \Friendica\Core\Console($this->container, $argv))->execute(); - } - - public function processJetstream(): void - { - $this->setupContainerForAddons(); - - $this->setupContainerForLogger(LogChannel::DAEMON); - - $this->setupLegacyServiceLocator(); - - $this->registerErrorHandler(); - Addon::loadAddons(); Hook::loadHooks(); - /** @var IManageConfigValues */ - $config = $this->container->create(IManageConfigValues::class); - - $config->reload(); - - /** @var Mode */ - $mode = $this->container->create(Mode::class); - - if ($mode->isInstall()) { - die("Friendica isn't properly installed yet.\n"); - } - - if (empty($config->get('jetstream', 'pidfile'))) { - die(<< [ - 'pidfile' => '/path/to/jetstream.pid', - ], - TXT); - } - - if (!Addon::isEnabled('bluesky')) { - die("Bluesky has to be enabled.\n"); - } - - $pidfile = $config->get('jetstream', 'pidfile'); - - if (in_array('start', (array)$_SERVER['argv'])) { - $daemonMode = 'start'; - } - - if (in_array('stop', (array)$_SERVER['argv'])) { - $daemonMode = 'stop'; - } - - if (in_array('status', (array)$_SERVER['argv'])) { - $daemonMode = 'status'; - } - - if (!isset($daemonMode)) { - die("Please use either 'start', 'stop' or 'status'.\n"); - } - - // Get options - $shortopts = 'f'; - $longopts = ['foreground']; - $options = getopt($shortopts, $longopts); - - $foreground = array_key_exists('f', $options) || array_key_exists('foreground', $options); - - if (empty($_SERVER['argv'][0])) { - die("Unexpected script behaviour. This message should never occur.\n"); - } - - $pid = null; - - if (is_readable($pidfile)) { - $pid = intval(file_get_contents($pidfile)); - } - - if (empty($pid) && in_array($daemonMode, ['stop', 'status'])) { - die("Pidfile wasn't found. Is jetstream running?\n"); - } - - if ($daemonMode == 'status') { - if (posix_kill($pid, 0)) { - die("Jetstream process $pid is running.\n"); - } - - unlink($pidfile); - - die("Jetstream process $pid isn't running.\n"); - } - - if ($daemonMode == 'stop') { - posix_kill($pid, SIGTERM); - - unlink($pidfile); - - Logger::notice('Jetstream process was killed', ['pid' => $pid]); - - die("Jetstream process $pid was killed.\n"); - } - - if (!empty($pid) && posix_kill($pid, 0)) { - die("Jetstream process $pid is already running.\n"); - } - - Logger::notice('Starting jetstream daemon.', ['pid' => $pid]); - - if (!$foreground) { - echo "Starting jetstream daemon.\n"; - - DBA::disconnect(); - - // Fork a daemon process - $pid = pcntl_fork(); - if ($pid == -1) { - echo "Daemon couldn't be forked.\n"; - Logger::warning('Could not fork daemon'); - exit(1); - } elseif ($pid) { - // The parent process continues here - if (!file_put_contents($pidfile, $pid)) { - echo "Pid file wasn't written.\n"; - Logger::warning('Could not store pid file'); - posix_kill($pid, SIGTERM); - exit(1); - } - echo 'Child process started with pid ' . $pid . ".\n"; - Logger::notice('Child process started', ['pid' => $pid]); - exit(0); - } - - // We now are in the child process - register_shutdown_function(function (): void { - posix_kill(posix_getpid(), SIGTERM); - posix_kill(posix_getpid(), SIGHUP); - }); - - // Make the child the main process, detach it from the terminal - if (posix_setsid() < 0) { - return; - } - - // Closing all existing connections with the outside - fclose(STDIN); - - // And now connect the database again - DBA::connect(); - } - - // Just to be sure that this script really runs endlessly - set_time_limit(0); - - // Now running as a daemon. - $jetstream = $this->container->create(Jetstream::class); - $jetstream->listen(); + (new \Friendica\Core\Console($this->container, $argv))->execute(); } public function processWorker(array $options): void diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php new file mode 100644 index 0000000000..1f50a92e50 --- /dev/null +++ b/src/Console/JetstreamDaemon.php @@ -0,0 +1,154 @@ +mode = $mode; + $this->config = $config; + $this->keyValue = $keyValue; + $this->jetstream = $jetstream; + $this->daemon = $daemon; + } + + protected function getHelp(): string + { + return <<mode->isInstall()) { + throw new RuntimeException("Friendica isn't properly installed yet"); + } + + $this->config->reload(); + + if (empty($this->config->get('jetstream', 'pidfile'))) { + throw new RuntimeException(<<< TXT + Please set jetstream.pidfile in config/local.config.php. For example: + + 'jetstream' => [ + 'pidfile' => '/path/to/jetstream.pid', + ], + TXT + ); + } + + if (!Addon::isEnabled('bluesky')) { + throw new RuntimeException("Bluesky has to be enabled.\n"); + } + + $pidfile = $this->config->get('jetstream', 'pidfile'); + + $daemonMode = $this->getArgument(0); + $foreground = $this->getOption(['f', 'foreground']) ?? false; + + if (empty($daemonMode)) { + throw new RuntimeException("Please use either 'start', 'stop' or 'status'"); + } + + $this->daemon->init($pidfile); + + if ($daemonMode == 'status') { + if ($this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s is running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + } else { + $this->out(sprintf("Daemon process %s isn't running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + } + return 0; + } + + if ($daemonMode == 'stop') { + if (!$this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s isn't running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 0; + } + + if ($this->daemon->stop()) { + $this->keyValue->set('worker_daemon_mode', false); + $this->out(sprintf("Daemon process %s was killed (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 0; + } + + return 1; + } + + if ($this->daemon->isRunning()) { + $this->out(sprintf("Daemon process %s is already running (%s)", $this->daemon->getPid(), $this->daemon->getPidfile())); + return 1; + } + + if ($daemonMode == "start") { + $this->out("Starting worker daemon"); + + $this->daemon->start(function () { + $this->jetstream->listen(); + }, $foreground); + + return 0; + } + + $this->err('Invalid command'); + $this->out($this->getHelp()); + return 1; + } +} diff --git a/src/Core/Console.php b/src/Core/Console.php index eec8b5fb67..3fabd92502 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -38,6 +38,7 @@ Commands: contact Contact management createdoxygen Generate Doxygen headers daemon Interact with the Friendica daemon + jetstream Interact with the Jetstream daemon dbstructure Do database updates docbloxerrorchecker Check the file tree for DocBlox errors extract Generate translation string file for the Friendica project (deprecated) @@ -77,6 +78,7 @@ HELP; 'contact' => Friendica\Console\Contact::class, 'createdoxygen' => Friendica\Console\CreateDoxygen::class, 'daemon' => Friendica\Console\Daemon::class, + 'jetstream' => Friendica\Console\JetstreamDaemon::class, 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, 'dbstructure' => Friendica\Console\DatabaseStructure::class, 'extract' => Friendica\Console\Extract::class, diff --git a/src/Protocol/ATProtocol/Jetstream.php b/src/Protocol/ATProtocol/Jetstream.php index 64a8397ddf..1326991f24 100755 --- a/src/Protocol/ATProtocol/Jetstream.php +++ b/src/Protocol/ATProtocol/Jetstream.php @@ -95,6 +95,7 @@ class Jetstream // @todo make the path configurable $this->client = new \WebSocket\Client('wss://jetstream1.us-west.bsky.network/subscribe?requireHello=true' . $cursor); $this->client->setTimeout($timeout); + $this->client->setLogger($this->logger); } catch (\WebSocket\ConnectionException $e) { $this->logger->error('Error while trying to establish the connection', ['code' => $e->getCode(), 'message' => $e->getMessage()]); echo "Connection wasn't established.\n"; @@ -365,7 +366,7 @@ class Jetstream } /** - * Route app.bsky.feed.post commits + * Route app.bsky.feed.post commits * * @param stdClass $data message object * @param integer $drift @@ -389,7 +390,7 @@ class Jetstream } /** - * Route app.bsky.feed.repost commits + * Route app.bsky.feed.repost commits * * @param stdClass $data message object * @param integer $drift @@ -413,7 +414,7 @@ class Jetstream } /** - * Route app.bsky.feed.like commits + * Route app.bsky.feed.like commits * * @param stdClass $data message object * @return void @@ -436,7 +437,7 @@ class Jetstream } /** - * Route app.bsky.actor.profile commits + * Route app.bsky.actor.profile commits * * @param stdClass $data message object * @return void @@ -463,7 +464,7 @@ class Jetstream } /** - * Route app.bsky.graph.follow commits + * Route app.bsky.graph.follow commits * * @param stdClass $data message object * @return void From 3e5872d0b1928a6dee1720e0daf84c6406f3289e Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:07:01 +0100 Subject: [PATCH 03/12] Add docs :-) --- src/System/Daemon.php | 58 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/System/Daemon.php b/src/System/Daemon.php index 61c281bd66..a9bbb22275 100644 --- a/src/System/Daemon.php +++ b/src/System/Daemon.php @@ -5,6 +5,9 @@ namespace Friendica\System; use Friendica\Database\Database; use Psr\Log\LoggerInterface; +/** + * class for direct interacting with the daemon commands + */ final class Daemon { private LoggerInterface $logger; @@ -12,11 +15,21 @@ final class Daemon private ?string $pidfile = null; private ?int $pid = null; + /** + * The PID of the current daemon (null if either not set or not found) + * + * @return int|null + */ public function getPid(): ?int { return $this->pid; } + /** + * The path to the PID file (null if not set) + * + * @return string|null + */ public function getPidfile(): ?string { return $this->pidfile; @@ -28,7 +41,14 @@ final class Daemon $this->dba = $dba; } - public function init($pidfile = null): void + /** + * Initialize the current daemon class with a given PID file + * + * @param string|null $pidfile the path to the PID file - using a given path if not directly set here + * + * @return void + */ + public function init(string $pidfile = null): void { if (!empty($pidfile)) { $this->pid = null; @@ -44,6 +64,14 @@ final class Daemon } } + /** + * Starts the daemon + * + * @param callable $daemonLogic the business logic of the daemon + * @param bool $foreground true, if started in foreground, otherwise spawned in the background + * + * @return bool true, if successfully started, otherwise false + */ public function start(callable $daemonLogic, bool $foreground = false): bool { $this->init(); @@ -100,6 +128,11 @@ final class Daemon return true; } + /** + * Checks, if the current daemon is running + * + * @return bool true, if the daemon is running, otherwise false (f.e no PID found, no PID file found, PID is not bound to a running process)) + */ public function isRunning(): bool { $this->init(); @@ -124,6 +157,11 @@ final class Daemon } } + /** + * Stops the daemon, if running + * + * @return bool true, if the daemon was successfully stopped or is already stopped, otherwise false + */ public function stop(): bool { $this->init(); @@ -133,14 +171,28 @@ final class Daemon return true; } - posix_kill($this->pid, SIGTERM); - unlink($this->pidfile); + if (!posix_kill($this->pid, SIGTERM)) { + $this->logger->warning("Cannot kill the given PID", ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + return false; + } + + if (!unlink($this->pidfile)) { + $this->logger->warning("Cannot delete the given PID file", ['pid' => $this->pid, 'pidfile' => $this->pidfile]); + return false; + } $this->logger->notice('daemon process was killed', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); return true; } + /** + * Sets the current daemon to sleep and checks the status afterward + * + * @param int $duration the duration of time for sleeping (in milliseconds) + * + * @return void + */ public function sleep(int $duration) { usleep($duration); From f2ce5647f2a58908317d53ce2ab792a7d5e4fd1b Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:14:25 +0100 Subject: [PATCH 04/12] Make PHP-CS super-happy :) --- src/App.php | 3 -- src/Console/Daemon.php | 3 +- src/Console/JetstreamDaemon.php | 2 +- src/Core/Console.php | 58 +++++++++++++-------------- src/Protocol/ATProtocol/Jetstream.php | 10 ++--- src/System/Daemon.php | 9 ++++- 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/App.php b/src/App.php index 57b32e082b..d1b37a1ccd 100644 --- a/src/App.php +++ b/src/App.php @@ -23,15 +23,12 @@ use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Worker\Repository\Process as ProcessRepository; -use Friendica\Database\DBA; use Friendica\Database\Definition\DbaDefinition; use Friendica\Database\Definition\ViewDefinition; use Friendica\Module\Maintenance; -use Friendica\Protocol\ATProtocol\Jetstream; use Friendica\Security\Authentication; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; -use Friendica\Core\Logger; use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\System; diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index e1810bb9cb..e57871b262 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -99,7 +99,8 @@ HELP; $this->config->reload(); if (empty($this->config->get('system', 'pidfile'))) { - throw new RuntimeException(<<< TXT + throw new RuntimeException( + <<< TXT Please set system.pidfile in config/local.config.php. For example: 'system' => [ diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index 1f50a92e50..af54530316 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -1,6 +1,6 @@ Friendica\Console\Addon::class, - 'archivecontact' => Friendica\Console\ArchiveContact::class, - 'autoinstall' => Friendica\Console\AutomaticInstallation::class, - 'cache' => Friendica\Console\Cache::class, - 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, - 'config' => Friendica\Console\Config::class, - 'contact' => Friendica\Console\Contact::class, - 'createdoxygen' => Friendica\Console\CreateDoxygen::class, - 'daemon' => Friendica\Console\Daemon::class, - 'jetstream' => Friendica\Console\JetstreamDaemon::class, - 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, - 'dbstructure' => Friendica\Console\DatabaseStructure::class, - 'extract' => Friendica\Console\Extract::class, + 'addon' => Friendica\Console\Addon::class, + 'archivecontact' => Friendica\Console\ArchiveContact::class, + 'autoinstall' => Friendica\Console\AutomaticInstallation::class, + 'cache' => Friendica\Console\Cache::class, + 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, + 'config' => Friendica\Console\Config::class, + 'contact' => Friendica\Console\Contact::class, + 'createdoxygen' => Friendica\Console\CreateDoxygen::class, + 'daemon' => Friendica\Console\Daemon::class, + 'jetstream' => Friendica\Console\JetstreamDaemon::class, + 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, + 'dbstructure' => Friendica\Console\DatabaseStructure::class, + 'extract' => Friendica\Console\Extract::class, 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class, - 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, - 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, - 'lock' => Friendica\Console\Lock::class, - 'maintenance' => Friendica\Console\Maintenance::class, - 'mergecontacts' => Friendica\Console\MergeContacts::class, - 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, - 'php2po' => Friendica\Console\PhpToPo::class, - 'postupdate' => Friendica\Console\PostUpdate::class, - 'po2php' => Friendica\Console\PoToPhp::class, - 'relay' => Friendica\Console\Relay::class, - 'relocate' => Friendica\Console\Relocate::class, - 'serverblock' => Friendica\Console\ServerBlock::class, - 'storage' => Friendica\Console\Storage::class, - 'test' => Friendica\Console\Test::class, - 'typo' => Friendica\Console\Typo::class, - 'user' => Friendica\Console\User::class, + 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, + 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, + 'lock' => Friendica\Console\Lock::class, + 'maintenance' => Friendica\Console\Maintenance::class, + 'mergecontacts' => Friendica\Console\MergeContacts::class, + 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, + 'php2po' => Friendica\Console\PhpToPo::class, + 'postupdate' => Friendica\Console\PostUpdate::class, + 'po2php' => Friendica\Console\PoToPhp::class, + 'relay' => Friendica\Console\Relay::class, + 'relocate' => Friendica\Console\Relocate::class, + 'serverblock' => Friendica\Console\ServerBlock::class, + 'storage' => Friendica\Console\Storage::class, + 'test' => Friendica\Console\Test::class, + 'typo' => Friendica\Console\Typo::class, + 'user' => Friendica\Console\User::class, ]; /** diff --git a/src/Protocol/ATProtocol/Jetstream.php b/src/Protocol/ATProtocol/Jetstream.php index 1326991f24..cb37fabeec 100755 --- a/src/Protocol/ATProtocol/Jetstream.php +++ b/src/Protocol/ATProtocol/Jetstream.php @@ -38,9 +38,9 @@ use stdClass; */ class Jetstream { - private $uids = []; - private $self = []; - private $capped = false; + private $uids = []; + private $self = []; + private $capped = false; /** @var LoggerInterface */ private $logger; @@ -213,8 +213,8 @@ class Jetstream if (!$this->capped && count($dids) < $did_limit) { $condition = ["`uid` = ? AND `network` = ? AND EXISTS(SELECT `author-id` FROM `post-user` WHERE `author-id` = `contact`.`id` AND `post-user`.`uid` != ?)", 0, Protocol::BLUESKY, 0]; - $contacts = Contact::selectToArray(['url'], $condition, ['order' => ['last-item' => true], 'limit' => $did_limit]); - $dids = $this->addDids($contacts, $uids, $did_limit, $dids); + $contacts = Contact::selectToArray(['url'], $condition, ['order' => ['last-item' => true], 'limit' => $did_limit]); + $dids = $this->addDids($contacts, $uids, $did_limit, $dids); } $this->keyValue->set('jetstream_did_count', count($dids)); diff --git a/src/System/Daemon.php b/src/System/Daemon.php index a9bbb22275..d8d658453c 100644 --- a/src/System/Daemon.php +++ b/src/System/Daemon.php @@ -1,5 +1,10 @@ pid < 0) { $this->logger->warning('Could not fork daemon'); return false; - } elseif ($this->pid) { + } else if ($this->pid) { // The parent process continues here if (!file_put_contents($this->pidfile, $this->pid)) { $this->logger->warning('Could not store pid file', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); From 2b5882855ba6adbff65c6ed6e1be3a2bb28be903 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:19:08 +0100 Subject: [PATCH 05/12] Make PHP-CS even more happy :) --- src/Console/JetstreamDaemon.php | 3 +- src/Core/Console.php | 62 ++++++++++++++++----------------- src/System/Daemon.php | 2 +- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index af54530316..554483b3e3 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -83,7 +83,8 @@ HELP; $this->config->reload(); if (empty($this->config->get('jetstream', 'pidfile'))) { - throw new RuntimeException(<<< TXT + throw new RuntimeException( + <<< TXT Please set jetstream.pidfile in config/local.config.php. For example: 'jetstream' => [ diff --git a/src/Core/Console.php b/src/Core/Console.php index b639d68bbb..30cae293ab 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -17,7 +17,7 @@ use Friendica\App; class Console extends \Asika\SimpleConsole\Console { // Disables the default help handling - protected $helpOptions = []; + protected $helpOptions = []; protected $customHelpOptions = ['h', 'help', '?']; /** @@ -69,36 +69,36 @@ HELP; } protected $subConsoles = [ - 'addon' => Friendica\Console\Addon::class, - 'archivecontact' => Friendica\Console\ArchiveContact::class, - 'autoinstall' => Friendica\Console\AutomaticInstallation::class, - 'cache' => Friendica\Console\Cache::class, - 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, - 'config' => Friendica\Console\Config::class, - 'contact' => Friendica\Console\Contact::class, - 'createdoxygen' => Friendica\Console\CreateDoxygen::class, - 'daemon' => Friendica\Console\Daemon::class, - 'jetstream' => Friendica\Console\JetstreamDaemon::class, - 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, - 'dbstructure' => Friendica\Console\DatabaseStructure::class, - 'extract' => Friendica\Console\Extract::class, - 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class, - 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, - 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, - 'lock' => Friendica\Console\Lock::class, - 'maintenance' => Friendica\Console\Maintenance::class, - 'mergecontacts' => Friendica\Console\MergeContacts::class, - 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, - 'php2po' => Friendica\Console\PhpToPo::class, - 'postupdate' => Friendica\Console\PostUpdate::class, - 'po2php' => Friendica\Console\PoToPhp::class, - 'relay' => Friendica\Console\Relay::class, - 'relocate' => Friendica\Console\Relocate::class, - 'serverblock' => Friendica\Console\ServerBlock::class, - 'storage' => Friendica\Console\Storage::class, - 'test' => Friendica\Console\Test::class, - 'typo' => Friendica\Console\Typo::class, - 'user' => Friendica\Console\User::class, + 'addon' => Friendica\Console\Addon::class, + 'archivecontact' => Friendica\Console\ArchiveContact::class, + 'autoinstall' => Friendica\Console\AutomaticInstallation::class, + 'cache' => Friendica\Console\Cache::class, + 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, + 'config' => Friendica\Console\Config::class, + 'contact' => Friendica\Console\Contact::class, + 'createdoxygen' => Friendica\Console\CreateDoxygen::class, + 'daemon' => Friendica\Console\Daemon::class, + 'jetstream' => Friendica\Console\JetstreamDaemon::class, + 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, + 'dbstructure' => Friendica\Console\DatabaseStructure::class, + 'extract' => Friendica\Console\Extract::class, + 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class, + 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, + 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, + 'lock' => Friendica\Console\Lock::class, + 'maintenance' => Friendica\Console\Maintenance::class, + 'mergecontacts' => Friendica\Console\MergeContacts::class, + 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, + 'php2po' => Friendica\Console\PhpToPo::class, + 'postupdate' => Friendica\Console\PostUpdate::class, + 'po2php' => Friendica\Console\PoToPhp::class, + 'relay' => Friendica\Console\Relay::class, + 'relocate' => Friendica\Console\Relocate::class, + 'serverblock' => Friendica\Console\ServerBlock::class, + 'storage' => Friendica\Console\Storage::class, + 'test' => Friendica\Console\Test::class, + 'typo' => Friendica\Console\Typo::class, + 'user' => Friendica\Console\User::class, ]; /** diff --git a/src/System/Daemon.php b/src/System/Daemon.php index d8d658453c..166d9400ef 100644 --- a/src/System/Daemon.php +++ b/src/System/Daemon.php @@ -96,7 +96,7 @@ final class Daemon if ($this->pid < 0) { $this->logger->warning('Could not fork daemon'); return false; - } else if ($this->pid) { + } elseif ($this->pid) { // The parent process continues here if (!file_put_contents($this->pidfile, $this->pid)) { $this->logger->warning('Could not store pid file', ['pid' => $this->pid, 'pidfile' => $this->pidfile]); From bc5d3b6c3aeb09a36d81bdf3c52ac68227cb9e08 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:20:56 +0100 Subject: [PATCH 06/12] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Console/Daemon.php | 2 +- src/Console/JetstreamDaemon.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index e57871b262..c2f1029e4a 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -151,7 +151,7 @@ HELP; } if ($daemonMode == "start") { - $this->out("Starting worker daemon"); + $this->out("Starting Friendica daemon"); $this->daemon->start(function () { $wait_interval = intval($this->config->get('system', 'cron_interval', 5)) * 60; diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index 554483b3e3..c7db468888 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -139,7 +139,7 @@ HELP; } if ($daemonMode == "start") { - $this->out("Starting worker daemon"); + $this->out("Starting Jetstream daemon"); $this->daemon->start(function () { $this->jetstream->listen(); From 320103af77ed2425841d01a352dd6b7e6f55b62d Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:26:48 +0100 Subject: [PATCH 07/12] Make PHP-CS even more happy :) --- src/Core/Console.php | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index 30cae293ab..6865a4d25a 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -70,34 +70,34 @@ HELP; protected $subConsoles = [ 'addon' => Friendica\Console\Addon::class, - 'archivecontact' => Friendica\Console\ArchiveContact::class, - 'autoinstall' => Friendica\Console\AutomaticInstallation::class, - 'cache' => Friendica\Console\Cache::class, - 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, - 'config' => Friendica\Console\Config::class, - 'contact' => Friendica\Console\Contact::class, - 'createdoxygen' => Friendica\Console\CreateDoxygen::class, - 'daemon' => Friendica\Console\Daemon::class, - 'jetstream' => Friendica\Console\JetstreamDaemon::class, - 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, - 'dbstructure' => Friendica\Console\DatabaseStructure::class, - 'extract' => Friendica\Console\Extract::class, - 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class, - 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, - 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, - 'lock' => Friendica\Console\Lock::class, - 'maintenance' => Friendica\Console\Maintenance::class, - 'mergecontacts' => Friendica\Console\MergeContacts::class, - 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, - 'php2po' => Friendica\Console\PhpToPo::class, - 'postupdate' => Friendica\Console\PostUpdate::class, - 'po2php' => Friendica\Console\PoToPhp::class, - 'relay' => Friendica\Console\Relay::class, - 'relocate' => Friendica\Console\Relocate::class, - 'serverblock' => Friendica\Console\ServerBlock::class, - 'storage' => Friendica\Console\Storage::class, - 'test' => Friendica\Console\Test::class, - 'typo' => Friendica\Console\Typo::class, + 'archivecontact' => Friendica\Console\ArchiveContact::class, + 'autoinstall' => Friendica\Console\AutomaticInstallation::class, + 'cache' => Friendica\Console\Cache::class, + 'clearavatarcache' => Friendica\Console\ClearAvatarCache::class, + 'config' => Friendica\Console\Config::class, + 'contact' => Friendica\Console\Contact::class, + 'createdoxygen' => Friendica\Console\CreateDoxygen::class, + 'daemon' => Friendica\Console\Daemon::class, + 'jetstream' => Friendica\Console\JetstreamDaemon::class, + 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class, + 'dbstructure' => Friendica\Console\DatabaseStructure::class, + 'extract' => Friendica\Console\Extract::class, + 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class, + 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class, + 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class, + 'lock' => Friendica\Console\Lock::class, + 'maintenance' => Friendica\Console\Maintenance::class, + 'mergecontacts' => Friendica\Console\MergeContacts::class, + 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class, + 'php2po' => Friendica\Console\PhpToPo::class, + 'postupdate' => Friendica\Console\PostUpdate::class, + 'po2php' => Friendica\Console\PoToPhp::class, + 'relay' => Friendica\Console\Relay::class, + 'relocate' => Friendica\Console\Relocate::class, + 'serverblock' => Friendica\Console\ServerBlock::class, + 'storage' => Friendica\Console\Storage::class, + 'test' => Friendica\Console\Test::class, + 'typo' => Friendica\Console\Typo::class, 'user' => Friendica\Console\User::class, ]; From 96332720e54c431eff4bdb9cd5e0963cd10fdbcd Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:34:20 +0100 Subject: [PATCH 08/12] Update messages.po ... --- view/lang/C/messages.po | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 4ce6bb5f02..c2319548f0 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2025.02-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-01 19:30+0000\n" +"POT-Creation-Date: 2025-01-01 23:33+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -646,6 +646,10 @@ msgstr "" msgid "Map" msgstr "" +#: src/App.php:397 +msgid "Apologies but the website is unavailable at the moment." +msgstr "" + #: src/App/Page.php:241 msgid "Delete this item?" msgstr "" From 1f9e1285af3deddef7546d201ab9fa6fbbb49283 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:48:02 +0100 Subject: [PATCH 09/12] Move Addon/Hook dependency where it belongs :) --- src/App.php | 3 --- src/Console/JetstreamDaemon.php | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index d1b37a1ccd..11392b2c5e 100644 --- a/src/App.php +++ b/src/App.php @@ -214,9 +214,6 @@ class App $this->registerTemplateEngine(); - Addon::loadAddons(); - Hook::loadHooks(); - (new \Friendica\Core\Console($this->container, $argv))->execute(); } diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index c7db468888..8dd726f4b9 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -13,6 +13,7 @@ use Friendica\App\Mode; use Friendica\Core\Addon; use Friendica\Core\Config\Capability\IManageConfigValues; use Asika\SimpleConsole\Console; +use Friendica\Core\Hook; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Protocol\ATProtocol\Jetstream; use Friendica\System\Daemon as SysDaemon; @@ -94,6 +95,9 @@ HELP; ); } + Addon::loadAddons(); + Hook::loadHooks(); + if (!Addon::isEnabled('bluesky')) { throw new RuntimeException("Bluesky has to be enabled.\n"); } From 9cdc1dde0e75db170284b9cc39472798bff9e012 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 00:49:56 +0100 Subject: [PATCH 10/12] remove dependency --- src/App.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/App.php b/src/App.php index 11392b2c5e..97d36ac5b4 100644 --- a/src/App.php +++ b/src/App.php @@ -17,9 +17,7 @@ use Friendica\App\Router; use Friendica\Capabilities\ICanCreateResponses; use Friendica\Capabilities\ICanHandleRequests; use Friendica\Content\Nav; -use Friendica\Core\Addon; use Friendica\Core\Config\Factory\Config; -use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Worker\Repository\Process as ProcessRepository; From efa912c373b5bcaae354f9edc4438e3de9c2ad78 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 13:03:28 +0100 Subject: [PATCH 11/12] Add deprecation notice --- bin/daemon.php | 2 ++ bin/jetstream.php | 1 + src/Console/Daemon.php | 4 ++++ src/Console/JetstreamDaemon.php | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/bin/daemon.php b/bin/daemon.php index 8f567edfb7..499bbc5d9b 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -5,6 +5,8 @@ * SPDX-FileCopyrightText: 2010-2024 the Friendica project * * SPDX-License-Identifier: AGPL-3.0-or-later + * + * @deprecated 2025.01 use bin/console.php daemon instead */ /** diff --git a/bin/jetstream.php b/bin/jetstream.php index c696d044b9..f1834c783b 100755 --- a/bin/jetstream.php +++ b/bin/jetstream.php @@ -6,6 +6,7 @@ * * SPDX-License-Identifier: AGPL-3.0-or-later * + * @deprecated 2025.01 use bin/console.php jetstream instead */ use Dice\Dice; diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index c2f1029e4a..6b1476a52e 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -90,6 +90,10 @@ HELP; protected function doExecute() { + if ($this->executable != 'bin/console.php') { + $this->out(sprintf("Deprecated use of '%s', use '%s daemon' instead", $this->executable, 'bin/console.php')); + } + if ($this->mode->isInstall()) { throw new RuntimeException("Friendica isn't properly installed yet"); } diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index 8dd726f4b9..2d591d52d9 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -77,6 +77,10 @@ HELP; protected function doExecute() { + if ($this->executable != 'bin/console.php') { + $this->out(sprintf("Deprecated use of '%s', use '%s jetstream' instead", $this->executable, 'bin/console.php')); + } + if ($this->mode->isInstall()) { throw new RuntimeException("Friendica isn't properly installed yet"); } From 0d2419e40207a26e007263475a78ab16a38ebb4d Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 2 Jan 2025 13:06:42 +0100 Subject: [PATCH 12/12] updated message --- src/Console/Daemon.php | 4 ++-- src/Console/JetstreamDaemon.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index 6b1476a52e..eac7b935a8 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -90,8 +90,8 @@ HELP; protected function doExecute() { - if ($this->executable != 'bin/console.php') { - $this->out(sprintf("Deprecated use of '%s', use '%s daemon' instead", $this->executable, 'bin/console.php')); + if ($this->executable !== 'bin/console.php') { + $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php daemon' instead", $this->executable)); } if ($this->mode->isInstall()) { diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index 2d591d52d9..133bf9c073 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -77,8 +77,8 @@ HELP; protected function doExecute() { - if ($this->executable != 'bin/console.php') { - $this->out(sprintf("Deprecated use of '%s', use '%s jetstream' instead", $this->executable, 'bin/console.php')); + if ($this->executable !== 'bin/console.php') { + $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php jetstream' instead", $this->executable)); } if ($this->mode->isInstall()) {