fix: update logic for waiting
This commit is contained in:
20
index.php
20
index.php
@ -11,9 +11,12 @@ if (str_starts_with($requestUri, '/api/')) {
|
||||
require __DIR__ . "/api/vendor/autoload.php";
|
||||
require __DIR__ . "/api/src/Services/LxdService.php";
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Zounar\PHPProxy\Proxy;
|
||||
use App\Services\LxdService;
|
||||
|
||||
// 🔹 Load .env config
|
||||
$dotenv = Dotenv::createImmutable(__DIR__ . '/api/');
|
||||
$dotenv->load();
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'] ?? '';
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
@ -25,8 +28,7 @@ $lxd = new LxdService();
|
||||
|
||||
// === Helper URLs ===
|
||||
$redirectBase = parseUrl("$host/app?auth=ok&redirect=" . urlencode(getFullUrl()));
|
||||
$waitingPage = parseUrl("$host/app/waiting?name=$container&redirect=" . urlencode($requestUri));
|
||||
|
||||
$waitingPage = parseUrl("$host/app/waiting?name=$container&redirect=" . urlencode(getFullUrl()));
|
||||
// === If container is missing or invalid ===
|
||||
if (!$container || !$lxd->containerExists($container)) {
|
||||
redirect($redirectBase);
|
||||
@ -39,9 +41,19 @@ if ($state !== 'Running') {
|
||||
redirect($redirectBase);
|
||||
}
|
||||
|
||||
// === Check container status ===
|
||||
$state = $lxd->getContainerState($container)['metadata']['status'] ?? 'Stopped';
|
||||
|
||||
if ($state !== 'Running') {
|
||||
redirect($redirectBase);
|
||||
}
|
||||
|
||||
// === Get container IP ===
|
||||
$ip = $lxd->getContainerIP($container);
|
||||
if (!$ip) {
|
||||
$nginx = $lxd->isServiceRunning($container, 'nginx');
|
||||
$mysql = $lxd->isServiceRunning($container, 'mysql');
|
||||
|
||||
if (!$ip || $nginx !== 'active' || $mysql !== 'active') {
|
||||
redirect($waitingPage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user