Skip to content

Commit

Permalink
[WebServerBundle] fixed server:start when already running
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 5, 2017
1 parent 126f4d9 commit 961d1ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Expand Up @@ -100,6 +100,12 @@ protected function execute(InputInterface $input, OutputInterface $output)

try {
$server = new WebServer();
if ($server->isRunning($input->getOption('pidfile'))) {
$io->error(sprintf('The web server is already running (listening on http://%s).', $server->getAddress($input->getOption('pidfile'))));

return 1;
}

$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));

if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output);
$server = new WebServer();
if ($server->isRunning($input->getOption('pidfile'))) {
$io->success('Web server still listening.');
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));
} else {
$io->warning('No web server is listening.');
}
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/WebServerBundle/WebServer.php
Expand Up @@ -109,6 +109,16 @@ public function stop($pidFile = null)
unlink($pidFile);
}

public function getAddress($pidFile = null)
{
$pidFile = $pidFile ?: $this->getDefaultPidFile();
if (!file_exists($pidFile)) {
return false;
}

return file_get_contents($pidFile);
}

public function isRunning($pidFile = null)
{
$pidFile = $pidFile ?: $this->getDefaultPidFile();
Expand Down

0 comments on commit 961d1ce

Please sign in to comment.