コード例 #1
0
 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);
     $config = new StandaloneServer\Config($params);
     $this->logServerConfig($logger, $config);
     $this->server = new StandaloneServer($config, $logger);
     $output->writeln($this->server->getCommand());
     return 1;
 }
コード例 #2
0
 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);
     $this->logServerConfig($logger, $config);
     $this->server = new StandaloneServer($config, $logger);
     $pid_file = $config->getPidFile();
     $log_file = $config->getLogFile();
     if (file_exists($log_file)) {
         $output->writeln('---------------------------------------------------------');
         $output->writeln("Content of log file ({$log_file})");
         $output->writeln('---------------------------------------------------------');
         $output->writeln($this->server->getOutput());
         $output->writeln('---------------------------------------------------------');
     }
     $isRunning = false;
     try {
         $pid = $this->server->getPid();
         if (!$this->server->isProcessRunning()) {
             $logger->error("Not running but pid file exists ({$pid_file}) and pid found ({$pid})");
             $msg = "Server not running but pid exists (pid: {$pid}) in pid_file ({$pid_file}). Please restart.";
         } else {
             $isRunning = true;
             $msg = "Server is running on port '{$port}' (pid: {$pid})";
         }
     } catch (PjbException\PidCorruptedException $e) {
         // Pid file corrupted
         $logger->critical("Cannot find server pid, your '{$pid_file}' is corrupted. Remove it.");
         $msg = 'Server not running (Critical error: pid file corrupted)';
     } catch (PjbException\PidNotFoundException $e) {
         $logger->info("Pid file '{$pid_file}' not exists, assuming server is down.");
         $msg = "Server not running on port '{$port}' (no pid file found)";
     } catch (\Exception $e) {
         $logger->error('Unexpected exception when testing pid file.');
         $msg = 'Cannot test server status';
     }
     $output->writeln($msg);
     return $isRunning ? 0 : 1;
 }
コード例 #3
0
 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("PJB server using port '{$port}' and config in '{$file}'");
     $this->logServerConfig($logger, $config);
     $this->server = new StandaloneServer($config, $logger);
     $this->server->restart();
     $logger->debug("Server output: \n" . $this->server->getOutput());
     $output->writeln("Server successfully restarted on port {$port}");
     return 0;
 }
コード例 #4
0
 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("Stopping the server on port '{$port}' and config file '{$file}'");
     $this->logServerConfig($logger, $config);
     $this->server = new StandaloneServer($config, $logger);
     $pid_file = $this->server->getConfig()->getPidFile();
     if (!file_exists($pid_file)) {
         $output->writeln("Server already stopped (pid_file '{$pid_file}' not found).");
     } else {
         $this->server->stop();
         $output->writeln("Server running on port {$port} successfully stopped");
     }
     return 0;
 }
コード例 #5
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();
 }