Skip to content

Commit 961d1ce

Browse files
committed
[WebServerBundle] fixed server:start when already running
1 parent 126f4d9 commit 961d1ce

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100

101101
try {
102102
$server = new WebServer();
103+
if ($server->isRunning($input->getOption('pidfile'))) {
104+
$io->error(sprintf('The web server is already running (listening on http://%s).', $server->getAddress($input->getOption('pidfile'))));
105+
106+
return 1;
107+
}
108+
103109
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
104110

105111
if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {

src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4747
$io = new SymfonyStyle($input, $output);
4848
$server = new WebServer();
4949
if ($server->isRunning($input->getOption('pidfile'))) {
50-
$io->success('Web server still listening.');
50+
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));
5151
} else {
5252
$io->warning('No web server is listening.');
5353
}

src/Symfony/Bundle/WebServerBundle/WebServer.php

+10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function stop($pidFile = null)
109109
unlink($pidFile);
110110
}
111111

112+
public function getAddress($pidFile = null)
113+
{
114+
$pidFile = $pidFile ?: $this->getDefaultPidFile();
115+
if (!file_exists($pidFile)) {
116+
return false;
117+
}
118+
119+
return file_get_contents($pidFile);
120+
}
121+
112122
public function isRunning($pidFile = null)
113123
{
114124
$pidFile = $pidFile ?: $this->getDefaultPidFile();

0 commit comments

Comments
 (0)