add: completion marker.

This commit is contained in:
Darshan
2026-01-25 11:33:05 +05:30
parent 85d2e08dc5
commit d4dd6cf634
3 changed files with 31 additions and 18 deletions
@@ -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) {
+6 -6
View File
@@ -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",
];
+21 -12
View File
@@ -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++) {