Ejemplo n.º 1
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $versionList = array();
     // ############################
     // System (LSB Version)
     // ############################
     $versionRow = array('system' => 'System', 'version' => UnixUtility::lsbSystemDescription());
     $versionList[] = array_values($versionRow);
     // ############################
     // PHP
     // ############################
     $versionList[] = array('PHP', phpversion());
     // ############################
     // MySQL
     // ############################
     $query = 'SHOW VARIABLES LIKE \'version\'';
     $versionRow = DatabaseConnection::getList($query);
     $versionList[] = array('MySQL', $versionRow['version']);
     // ############################
     // Apache
     // ############################
     $versionRow = array('system' => 'Apache', 'version' => 'Unknown');
     $command = new CommandBuilder('apache2ctl', '-v');
     $command->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_NO_STDERR);
     $execOutput = $command->execute()->getOutput();
     foreach ($execOutput as $execOutputLine) {
         if (strpos($execOutputLine, ':') !== false) {
             list($tmpKey, $tmpVersion) = explode(':', trim($execOutputLine), 2);
             switch (strtolower($tmpKey)) {
                 case 'server version':
                     $versionRow['version'] = trim($tmpVersion);
                     break;
             }
         }
     }
     $versionList[] = array_values($versionRow);
     // ############################
     // Docker
     // ############################
     $versionRow = array('system' => 'Docker', 'version' => \CliTools\Utility\UnixUtility::dockerVersion());
     $versionList[] = array_values($versionRow);
     // ############################
     // CliTools
     // ############################
     $versionList[] = array('CliTools', CLITOOLS_COMMAND_VERSION);
     // ########################
     // Output
     // ########################
     /** @var \Symfony\Component\Console\Helper\Table $table */
     $table = new Table($output);
     $table->setHeaders(array('System', 'Version'));
     foreach ($versionList as $versionRow) {
         $table->addRow(array_values($versionRow));
     }
     $table->render();
     return 0;
 }
Ejemplo n.º 2
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->elevateProcess($input, $output);
     $pid = null;
     $grep = $input->getArgument('grep');
     $command = new CommandBuilder('strace', '-f');
     $command->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_ALL_STDOUT);
     $output->writeln('<h2>Starting process stracing</h2>');
     if (empty($pid)) {
         list($pidList, $processList) = $this->buildProcessList();
         if ($input->getOption('all')) {
             $pid = 'all';
         } else {
             try {
                 $question = new ChoiceQuestion('Please choose process for tracing', $processList);
                 $question->setMaxAttempts(1);
                 $questionDialog = new QuestionHelper();
                 $pid = $questionDialog->ask($input, $output, $question);
             } catch (\InvalidArgumentException $e) {
                 // Invalid value, just stop here
                 throw new \CliTools\Exception\StopException(1);
             }
         }
     }
     if (!empty($pid)) {
         switch ($pid) {
             case 'all':
                 $command->addArgumentTemplate('-p %s', implode(',', $pidList));
                 break;
             default:
                 $command->addArgumentTemplate('-p %s', $pid);
                 break;
         }
         // Stats
         if ($input->getOption('c')) {
             $command->addArgument('-c');
         }
         // Relative time
         if ($input->getOption('r')) {
             $command->addArgument('-r');
         } else {
             $command->addArgument('-tt');
         }
         // System trace filter
         if ($input->getOption('e')) {
             $command->addArgumentTemplate('-e %s', $input->getOption('e'));
         }
         // Add grep
         if (!empty($grep)) {
             $grepCommand = new CommandBuilder('grep');
             $grepCommand->addArgument('--color=auto')->addArgument($grep);
             $command->addPipeCommand($grepCommand);
         }
         $command->executeInteractive();
     }
     return 0;
 }
Ejemplo n.º 3
0
 /**
  * Send wall message
  *
  * @param  string $message Message
  */
 public static function sendWallMessage($message)
 {
     $wall = new CommandBuilder('wall');
     $wall->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_NULL);
     $command = new CommandBuilder('echo');
     $command->addArgument($message)->addPipeCommand($wall);
     $command->execute();
 }