protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getConsoleLogger($output);
     $file = $input->getArgument('config-file');
     // Test if config file exists
     if (!file_exists($file) || !is_readable($file)) {
         $msg = "Configuration file '{$file}' does not exists or is not readable'";
         throw new \InvalidArgumentException($msg);
     }
     $params = (include $file);
     $port = $params['port'];
     $config = new StandaloneServer\Config($params);
     $logger->notice("Starting the server on port '{$port}' and config file '{$file}'");
     $this->logServerConfig($logger, $config);
     $this->server = new StandaloneServer($config, $logger);
     if ($this->server->isProcessRunning()) {
         $pid = $this->server->getPid();
         $output->writeln("PjbServer is already running on port {$port} with pid {$pid}, skipping start");
     } else {
         $this->server->start();
         $output->writeln("Server successfully started on port {$port}");
     }
     return 0;
 }
 public function testStartServerThrowsPortUnavailableException()
 {
     $this->assertFalse($this->server->isStarted());
     $this->server->start();
     $this->assertTrue($this->server->isStarted());
     $pid_file = $this->server->getConfig()->getPidFile();
     $this->assertFileExists($pid_file);
     $this->setExpectedException(Exception\PortUnavailableException::class);
     // Test starting another instance on the same port
     $runningServerConfig = $this->server->getConfig()->toArray();
     // Start the original server
     $this->server->start();
     $config = array_merge($runningServerConfig, ['log_file' => $this->server->getConfig()->getLogFile() . '.extra.log', 'pid_file' => $this->server->getConfig()->getPidFile() . '.extra.pid']);
     // Other server on same port
     // should throw a port unavailable exception
     $otherServer = new StandaloneServer(new StandaloneServer\Config($config));
     $otherServer->start();
 }