directoryList->getPath(DirectoryList::VAR_DIR) . '/magesail.pid'; $hadPidFile = \is_file($pidFile); $wasRunning = false; if ($hadPidFile) { $pid = (int) trim((string) file_get_contents($pidFile)); $wasRunning = $pid > 0 && $this->tunnelStatus->isProcessAlive($pid); } if (!$wasRunning && $hadPidFile) { $this->tunnelStatus->cleanupStaleState(); $this->magesailLog->add('Cron: tunnel process gone; cleaned PID/key files'); $this->logger->warning('Magesail tunnel crashed; cleaned up PID files.'); $autoRestart = (bool) $this->scopeConfig->getValue(self::XML_AUTO_RESTART); if ($autoRestart) { $secure = (bool) $this->scopeConfig->getValue('magesail/settings/mode'); $port = filter_var($this->scopeConfig->getValue('magesail/settings/port') ?: 80, FILTER_VALIDATE_INT); if ($port && \in_array($port, [80, 443], true)) { $result = $this->tunnelManager->start($port, $secure); if ($result['ok']) { $this->magesailLog->add(sprintf('Cron auto-restart OK PID %s', $result['pid'])); $this->logger->info('Magesail tunnel auto-restarted by cron.'); } else { $this->magesailLog->add('Cron auto-restart failed: ' . ($result['error'] ?? 'unknown')); $this->logger->warning('Magesail auto-restart failed: ' . ($result['error'] ?? '')); } } else { $this->magesailLog->add('Cron auto-restart skipped: invalid port'); } } } $this->logger->info('Magesail cron monitor executed.'); } }