protected function execute(InputInterface $input, OutputInterface $output) { try { if (!$input->getOption('allow-root')) { $aProcessUser = posix_getpwuid(posix_geteuid()); if ($aProcessUser['name'] == 'root') { throw new \InvalidArgumentException('You can however run a command with ' . 'sudo using --allow-root option'); } } DaemonUtils::configCheck(); //Check daemons $daemons = DaemonUtils::getDaemonsFromConfig(); foreach ($daemons as $daemon) { if (!$daemon instanceof DaemonizerInterface) { throw new \Exception('Invalid [cli-daemonizer.php] file: file contain not-implementer ' . 'DaemonizerInterface class'); } DaemonUtils::checkScheduleItem($daemon->getSchedule(), get_class($daemon)); } $id = mt_rand(1, 100000); shell_exec(DAEMON_FILE . " internal:master --id={$id} > /dev/null 2>&1 &"); $output->writeln("<info>Daemon started</info>"); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }
public function testConfigChecker() { $this->assertEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem('* * * * *')); $this->assertEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem('59 * * * *')); $this->assertEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem(array(0, 1, 2, 3, 4, 5, 10, 12, 15, 19, 23))); $this->assertEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem(1)); $this->assertEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem()); $this->assertNotEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem('* * * * * 1999')); $this->assertNotEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem('60 * * * *')); $this->assertNotEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem('61 * * * *')); $this->assertNotEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem(array(1, 25))); $this->assertNotEquals(false, \Brainfit\Daemonizer\DaemonUtils::checkScheduleItem(array(-1, 25))); }