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>'); } }
protected function execute(InputInterface $input, OutputInterface $output) { try { $id = $input->getOption('id'); DaemonUtils::configCheck(); $daemons = DaemonUtils::getDaemonsFromConfig(); file_put_contents(DaemonUtils::getPidFilename(), getmypid() . ',' . $id); $loop = \React\EventLoop\Factory::create(); $master = new MasterController($loop, new ChildController()); foreach ($daemons as $daemon) { if (!$daemon instanceof DaemonizerInterface) { throw new \Exception('Invalid [cli-daemonizer.php] file: file contain not-implementer ' . 'DaemonizerInterface class'); } $master->attach($daemon); } $master->start(); $loop->run(); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }