Merge pull request #247 from raistlin/Fix_Daemonise

Fix daemonise
This commit is contained in:
Steve B 2014-01-04 02:50:38 -08:00
commit 2b360675b6
3 changed files with 33 additions and 7 deletions

View file

@ -10,14 +10,13 @@
namespace PHPCI\Command;
use Monolog\Logger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use b8\Store\Factory;
use PHPCI\Builder;
use PHPCI\BuildFactory;
/**
* Daemon that loops and call the run-command.
@ -27,6 +26,26 @@ use PHPCI\BuildFactory;
*/
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()
{
$this
@ -43,14 +62,19 @@ class DaemoniseCommand extends Command
$command = sprintf($cmd, getmypid(), PHPCI_DIR);
exec($command);
$this->output = $output;
$this->run = true;
$this->sleep = 0;
$runner = new RunCommand;
$runner = new RunCommand($this->logger);
$in = new ArgvInput(array());
while ($this->run) {
$buildCount = 0;
try {
$buildCount = $runner->execute($input, $output);
$buildCount = $runner->run($in, $output);
} catch (\Exception $e) {
var_dump($e);
}

View file

@ -68,7 +68,7 @@ class RunCommand extends Command
// For verbose mode we want to output all informational and above
// messages to the symphony output interface.
if ($input->getOption('verbose')) {
if ($input->hasOption('verbose')) {
$this->logger->pushHandler(
new OutputLogHandler($this->output, Logger::INFO)
);

View file

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