logger = $logger; $this->shell = $shell; $this->directoryList = $directoryList; } public function execute() { $pidFile = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/magesail.pid'; if (file_exists($pidFile)) { $pid = (int) trim(file_get_contents($pidFile)); try { $this->shell->execute("ps -p $pid > /dev/null 2>&1"); $isRunning = true; } catch (\Exception $e) { $isRunning = false; } if (!$isRunning) { unlink($pidFile); $keyFile = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/magesail.key'; if (file_exists($keyFile)) { unlink($keyFile); } $this->logger->warning('Magesail tunnel crashed; cleaned up PID files.'); // Optional: Auto-restart here if config allows } } $this->logger->info('Magesail cron monitor executed.'); } }