/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Restart workers</info>');
     $monitoring = WorkerMonitoring::init();
     if ($monitoring->isMaster()) {
         $action = self::ACTION_RESTART;
         $monitoring->updateAction($action);
         if ($input->getOption('wait-response')) {
             while ($action === self::ACTION_RESTART) {
                 sleep(5);
                 $action = $monitoring->getAction();
             }
             $output->writeln('restarted');
         } else {
             $output->writeln('signal sent');
         }
     } else {
         $output->writeln('not master node');
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $monitoring = WorkerMonitoring::init();
     $monitoring->updateAction(self::ACTION_MONITORING);
     $statusManager = $this->getStatusManager();
     $statusManager->setOptions(ConfigManager::getConfig()->get('worker_manager.options') ?: []);
     $updateManager = $this->getUpdateManager();
     $logger = $this->getLogger();
     list($workers, $VMConfigs) = $statusManager->initData();
     $output->writeln('Worker monitoring: <info>running</info>');
     $output->write('Balancing: ');
     if ($monitoring->isBalancing()) {
         $output->writeln('<info>yes</info>');
     } else {
         $output->writeln('<comment>no</comment>');
     }
     $output->writeln('Node name: <info>' . $monitoring->getName() . '</info>');
     $output->writeln('Node PID: <info>' . $monitoring->getPID() . '</info>');
     $output->write('Status: ');
     do {
         if ($monitoring->isMaster()) {
             $action = $monitoring->getAction();
             $output->write('<info>master[' . $action . ']</info> ');
             $statusManager->updateStatus($workers, $VMConfigs);
             switch ($action) {
                 case self::ACTION_MONITORING:
                     /** @var \WorkerManager\Model\WorkerConfig $worker */
                     foreach ($workers as $worker) {
                         $updateManager->update($worker);
                         if ($logger) {
                             $logger->logWorker($worker);
                         }
                     }
                     if ($logger) {
                         foreach ($VMConfigs as $VMConfig) {
                             $logger->logVM($VMConfig);
                         }
                     }
                     break;
                 case self::ACTION_RESTART:
                     $output->writeln('Restarting workers...');
                     /** @var \WorkerManager\Model\VMConfig $VMConfig */
                     foreach ($VMConfigs as $VMConfig) {
                         $output->writeln('Restart ' . $VMConfig->getName());
                         $updateManager->restartWorkers($VMConfig, function ($response) use($output) {
                             $output->writeln($response);
                         });
                     }
                     $monitoring->updateAction(static::ACTION_MONITORING);
                     break;
             }
         } else {
             $output->write('<comment>slave</comment> ');
         }
         $monitoring->wait();
     } while ($this->isAlive());
 }