config = new Config('', '', ''); $this->logger = new Logger('pfatt-5268AC'); $this->ngControl = new NgController($this->logger); } /** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output): int { $this->logger->setOutput($output); $this->logger->info('Starting 5268AC ping monitor ...'); register_shutdown_function(function () { $this->logger->info('Stopping 5268AC ping monitor ...'); }); while ($input->isInteractive()) { if ($this->ping()) { $this->ngControl->ngRmHook(); } elseif (!$this->ngControl->ngIsConnected()) { $this->ngControl->ngConnect(); } sleep(5); } return Command::SUCCESS; } private function ping(): int { $process = proc_open('/sbin/ping -t2 -q -c1 ' . $this->config->getPingHost(), [], $pipes); if ($process) { return proc_close($process); } return 1; } }