scopeConfig->getValue(self::XML_AUTO_RESTART); foreach ($this->tunnelRegistry->listTunnels() as $tunnel) { $tunnelId = (string) ($tunnel['id'] ?? ''); if ($tunnelId === '') { continue; } $pidFile = $this->tunnelProcessPaths->getPidFilePath($tunnelId); if (!\is_file($pidFile)) { continue; } $pid = (int) trim((string) file_get_contents($pidFile)); $wasRunning = $pid > 0 && $this->tunnelStatus->isProcessAlive($pid); if ($wasRunning) { continue; } $this->tunnelStatus->cleanupStaleStateForTunnel($tunnelId); $this->magesailLog->add(sprintf('Cron: tunnel %s process gone; cleaned PID/key files', $tunnelId)); $this->logger->warning(sprintf('MageSail tunnel %s crashed; cleaned up PID files.', $tunnelId)); if ($autoRestart) { $result = $this->tunnelManager->start($tunnelId); if ($result['ok'] ?? false) { $this->magesailLog->add(sprintf('Cron auto-restart OK tunnel %s PID %s', $tunnelId, $result['pid'] ?? '')); $this->logger->info(sprintf('MageSail tunnel %s auto-restarted by cron.', $tunnelId)); } else { $this->magesailLog->add(sprintf( 'Cron auto-restart failed tunnel %s: %s', $tunnelId, $result['error'] ?? 'unknown' )); $this->logger->warning(sprintf( 'MageSail auto-restart failed for %s: %s', $tunnelId, $result['error'] ?? '' )); } } } $this->logger->info('MageSail cron monitor executed.'); } }