2013-06-09 21:11:22 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
* nohup PHPCI_DIR/console phpci:start-daemon > /dev/null 2>&1 &
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://www.phptesting.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PHPCI\Command;
|
|
|
|
|
2014-01-04 10:19:55 +01:00
|
|
|
use Monolog\Logger;
|
2013-06-09 21:11:22 +02:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2014-01-04 10:19:55 +01:00
|
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
2013-06-09 21:11:22 +02:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Daemon that loops and call the run-command.
|
|
|
|
* @author Gabriel Baker <gabriel.baker@autonomicpilot.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Console
|
|
|
|
*/
|
|
|
|
class DaemoniseCommand extends Command
|
|
|
|
{
|
2014-01-04 10:19:55 +01:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
2013-06-09 21:11:22 +02:00
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('phpci:daemonise')
|
|
|
|
->setDescription('Starts the daemon to run commands.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loops through running.
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$cmd = "echo %s > '%s/daemon/daemon.pid'";
|
|
|
|
$command = sprintf($cmd, getmypid(), PHPCI_DIR);
|
|
|
|
exec($command);
|
|
|
|
|
2014-01-04 10:19:55 +01:00
|
|
|
$this->output = $output;
|
2013-06-09 21:11:22 +02:00
|
|
|
$this->run = true;
|
|
|
|
$this->sleep = 0;
|
2014-01-04 10:19:55 +01:00
|
|
|
$runner = new RunCommand($this->logger);
|
|
|
|
|
|
|
|
$in = new ArgvInput(array());
|
2013-06-09 21:11:22 +02:00
|
|
|
|
|
|
|
while ($this->run) {
|
|
|
|
|
2014-01-04 10:19:55 +01:00
|
|
|
$buildCount = 0;
|
|
|
|
|
2013-06-09 21:11:22 +02:00
|
|
|
try {
|
2014-01-04 10:19:55 +01:00
|
|
|
$buildCount = $runner->run($in, $output);
|
2013-06-09 21:11:22 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
var_dump($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == $buildCount && $this->sleep < 15) {
|
|
|
|
$this->sleep++;
|
2013-10-10 02:01:06 +02:00
|
|
|
} elseif (1 < $this->sleep) {
|
2013-06-09 21:11:22 +02:00
|
|
|
$this->sleep--;
|
|
|
|
}
|
|
|
|
echo '.'.(0 === $buildCount?'':'build');
|
|
|
|
sleep($this->sleep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when log entries are made in Builder / the plugins.
|
|
|
|
* @see \PHPCI\Builder::log()
|
|
|
|
*/
|
|
|
|
public function logCallback($log)
|
|
|
|
{
|
|
|
|
$this->output->writeln($log);
|
|
|
|
}
|
|
|
|
}
|