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; }
public function testGetPidCorrupted() { $config = $this->server->getConfig(); $pid_file = $config->getPidFile(); $this->server->start(); $pid = $this->server->getPid(); $this->assertInternalType('int', $pid); // pretend pid file is corrupted file_put_contents($pid_file, 'invalidpid'); try { $this->server->getPid(); $this->assertFalse(true, "PidCorrupted exception was not throwned"); } catch (\PjbServer\Tools\Exception\PidCorruptedException $e) { $this->assertTrue(true, "PID Corrupted exception was correctly thrown"); } // restore pid file_put_contents($pid_file, $pid); $this->assertInternalType('int', $this->server->getPid()); $this->assertEquals($pid, $this->server->getPid()); $this->server->stop(); }