Beispiel #1
0
use Arara\Process\Context;
use Arara\Process\Control;
$daemon = new Daemon(function (Daemon $daemon, Control $control) {
    openlog($daemon->getOption('name'), LOG_PID | LOG_PERROR, LOG_LOCAL0);
    $control->flush(60);
});
$daemon->bind(Daemon::EVENT_SUCCESS, function () {
    syslog(LOG_INFO, 'Daemon was successfully finished');
});
$daemon->bind(Daemon::EVENT_ERROR | Daemon::EVENT_FAILURE, function (Context $context) {
    syslog(LOG_ERR, $context->exception->getMessage());
});
$daemon->bind(Daemon::EVENT_FINISH, function () {
    closelog();
});
$daemon->setOption('lock_dir', __DIR__);
$control = new Control();
$process = new Child($daemon, $control);
try {
    $args = $_SERVER['argv'];
    $script = array_shift($args);
    $usageMessage = sprintf('php %s {start|stop|status}', $script);
    if (empty($args)) {
        throw new DomainException($usageMessage);
    }
    $action = array_shift($args);
    switch ($action) {
        case 'start':
            $process->start();
            fwrite(STDOUT, 'Started' . PHP_EOL);
            break;
Beispiel #2
0
 /**
  * @expectedException Arara\Process\Exception\InvalidArgumentException
  * @expectedExceptionMessage "chumba" is not a valid option
  */
 public function testShouldThrowsAnExceptinoWhenDefiningANonExistingOption()
 {
     $daemon = new Daemon(function () {
     });
     $daemon->setOption('chumba', '\\o/');
 }