Fix daemonise crash.

This commit is contained in:
Raul Ferriz 2014-01-04 10:19:55 +01:00
parent 8bc043065a
commit 4b50b9eb77
2 changed files with 32 additions and 3 deletions

View file

@ -10,7 +10,9 @@
namespace PHPCI\Command; namespace PHPCI\Command;
use Monolog\Logger;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -27,6 +29,26 @@ use PHPCI\BuildFactory;
*/ */
class DaemoniseCommand extends Command class DaemoniseCommand extends Command
{ {
/**
* @var Logger
*/
protected $logger;
/**
* @var OutputInterface
*/
protected $output;
/**
* @param \Monolog\Logger $logger
* @param string $name
*/
public function __construct(Logger $logger, $name = null)
{
parent::__construct($name);
$this->logger = $logger;
}
protected function configure() protected function configure()
{ {
$this $this
@ -43,14 +65,19 @@ class DaemoniseCommand extends Command
$command = sprintf($cmd, getmypid(), PHPCI_DIR); $command = sprintf($cmd, getmypid(), PHPCI_DIR);
exec($command); exec($command);
$this->output = $output;
$this->run = true; $this->run = true;
$this->sleep = 0; $this->sleep = 0;
$runner = new RunCommand; $runner = new RunCommand($this->logger);
$in = new ArgvInput(array());
while ($this->run) { while ($this->run) {
$buildCount = 0;
try { try {
$buildCount = $runner->execute($input, $output); $buildCount = $runner->run($in, $output);
} catch (\Exception $e) { } catch (\Exception $e) {
var_dump($e); var_dump($e);
} }

View file

@ -15,6 +15,8 @@ require('bootstrap.php');
use PHPCI\Command\DaemoniseCommand; use PHPCI\Command\DaemoniseCommand;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
$loggerConfig = \PHPCI\Helper\LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php");
$application = new Application(); $application = new Application();
$application->add(new DaemoniseCommand); $application->add(new DaemoniseCommand($loggerConfig->getFor('DaemoniseCommand')));
$application->run(); $application->run();