From d4dd6cf634aad69ced115f32364821fc1f3ed685 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 25 Jan 2026 11:33:05 +0530 Subject: [PATCH] add: completion marker. --- .../Platform/Installer/HttpHandler.php | 4 +++ src/Appwrite/Platform/Installer/Server.php | 12 +++---- src/Appwrite/Platform/Tasks/Install.php | 33 ++++++++++++------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Appwrite/Platform/Installer/HttpHandler.php b/src/Appwrite/Platform/Installer/HttpHandler.php index 18a9b5bed1..7016445e90 100644 --- a/src/Appwrite/Platform/Installer/HttpHandler.php +++ b/src/Appwrite/Platform/Installer/HttpHandler.php @@ -180,6 +180,8 @@ class HttpHandler $this->state->updateGlobalLock($installId, Server::STATUS_COMPLETED); } + @touch(Server::INSTALLER_COMPLETE_FILE); + if ($sessionSecret) { $isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'); @@ -314,6 +316,8 @@ class HttpHandler $installId = bin2hex(random_bytes(8)); } + @unlink(Server::INSTALLER_COMPLETE_FILE); + try { $lockResult = $this->state->reserveGlobalLock($installId); } catch (\Throwable $e) { diff --git a/src/Appwrite/Platform/Installer/Server.php b/src/Appwrite/Platform/Installer/Server.php index fa60e0c127..14a815cac4 100644 --- a/src/Appwrite/Platform/Installer/Server.php +++ b/src/Appwrite/Platform/Installer/Server.php @@ -11,11 +11,12 @@ use Appwrite\Platform\Installer\Runtime\State; class Server { public const int INSTALLER_WEB_PORT = 20080; - public const int INSTALLER_WEB_PORT_INTERNAL = 20080; + public const string INSTALLER_WEB_HOST = '0.0.0.0'; // temp files for state and config management! public const string INSTALLER_LOCK_FILE = '/tmp/appwrite-install-lock.json'; public const string INSTALLER_CONFIG_FILE = '/tmp/appwrite-installer-config.json'; + public const string INSTALLER_COMPLETE_FILE = '/tmp/appwrite-installer-complete'; public const string STEP_ENV_VARS = 'env-vars'; public const string STEP_CONFIG_FILES = 'config-files'; @@ -91,9 +92,8 @@ class Server } $this->state->applyEnvConfig($cfg); - $isLocalInstall = $cfg->isLocal(); - $host = '0.0.0.0'; - $port = $isLocalInstall ? (string)self::INSTALLER_WEB_PORT_INTERNAL : (string)self::INSTALLER_WEB_PORT; + $host = self::INSTALLER_WEB_HOST; + $port = (string)self::INSTALLER_WEB_PORT; $isMock = $cfg->isMock(); if (isset($opts['clean'])) { @@ -114,7 +114,7 @@ class Server private function printInstallerUrl(bool $isMock, string $host, string $port): void { - $displayHost = $host === '0.0.0.0' ? 'localhost' : $host; + $displayHost = $host === self::INSTALLER_WEB_HOST ? 'localhost' : $host; $url = "http://$displayHost:$port"; $message = $isMock ? "Mock mode enabled: $url" : "Open $url"; fwrite(STDOUT, $message . PHP_EOL); @@ -298,7 +298,7 @@ class Server '-i', '--rm', '--name', $container, - '-p', "127.0.0.1:$port:" . self::INSTALLER_WEB_PORT_INTERNAL, + '-p', "127.0.0.1:$port:" . self::INSTALLER_WEB_PORT, '--volume', '/var/run/docker.sock:/var/run/docker.sock', '--volume', "$volumePath:/usr/src/code:rw", ]; diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index c21326084c..93132a87c8 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -248,10 +248,10 @@ class Install extends Action protected function startWebServer(string $defaultHTTPPort, string $defaultHTTPSPort, string $organization, string $image, bool $noStart, array $vars, bool $isUpgrade = false, ?string $lockedDatabase = null): void { - $host = '0.0.0.0'; - $port = $this->isLocalInstall() - ? InstallerServer::INSTALLER_WEB_PORT_INTERNAL - : InstallerServer::INSTALLER_WEB_PORT; + $host = InstallerServer::INSTALLER_WEB_HOST; + $port = InstallerServer::INSTALLER_WEB_PORT; + + @unlink(InstallerServer::INSTALLER_COMPLETE_FILE); $this->setInstallerConfig([ 'defaultHttpPort' => $defaultHTTPPort, @@ -292,14 +292,8 @@ class Install extends Action return; } - // Wait for the server process to finish - while (true) { - $handle = @fsockopen('localhost', $port, $errno, $errstr, 1); - if ($handle === false) { - break; - } - \fclose($handle); - \sleep(1); + if ($this->isInstallationComplete($port)) { + Console::success('Installation completed.'); } } @@ -899,6 +893,21 @@ class Install extends Action return $this->isLocalInstall() ? '.env.web-installer' : '.env'; } + private function isInstallationComplete(int $port): bool + { + while (true) { + if (file_exists(InstallerServer::INSTALLER_COMPLETE_FILE)) { + return true; + } + $handle = @fsockopen('localhost', $port, $errno, $errstr, 1); + if ($handle === false) { + return false; + } + \fclose($handle); + \sleep(1); + } + } + private function waitForWebServer(int $port): bool { for ($attempt = 0; $attempt < self::WEB_SERVER_CHECK_ATTEMPTS; $attempt++) {