| @@ 15-80 (lines=66) @@ | ||
| 12 | /** |
|
| 13 | * Class StreamCommand. |
|
| 14 | */ |
|
| 15 | class StreamCommand extends Command |
|
| 16 | { |
|
| 17 | protected $_config; |
|
| 18 | protected $_projectPath; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Configure the stream command. |
|
| 22 | */ |
|
| 23 | protected function configure() |
|
| 24 | { |
|
| 25 | $this->_projectPath = getcwd(); |
|
| 26 | $this->setName('log:stream'); |
|
| 27 | $this->setDescription('Stream a specific server log'); |
|
| 28 | $this->addArgument('log', InputArgument::REQUIRED, 'access or error'); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @param InputInterface $input |
|
| 33 | * @param OutputInterface $output |
|
| 34 | * |
|
| 35 | * @return ProcessCommand |
|
| 36 | */ |
|
| 37 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 38 | { |
|
| 39 | $log = $input->getArgument('log'); |
|
| 40 | ||
| 41 | $output->writeln('<info>Streaming '.ucwords($log).' Log</info>'); |
|
| 42 | $command = $this->getCommand(new Config($output), $log); |
|
| 43 | if (!$command) { |
|
| 44 | return $output->writeln('<error>Command not available for this application</error>'); |
|
| 45 | } |
|
| 46 | ||
| 47 | $pCommand = "vagrant ssh -c '".$command."'"; |
|
| 48 | ||
| 49 | return new ProcessCommand($pCommand, $this->_projectPath, $output); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param Config $config |
|
| 54 | * @param $log |
|
| 55 | * |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | private function getCommand(Config $config, $log) |
|
| 59 | { |
|
| 60 | $server = $config->_config['magestead']['server']; |
|
| 61 | $os = $config->_config['magestead']['os']; |
|
| 62 | ||
| 63 | $location = $this->getLogLocation($server, $os); |
|
| 64 | $command = 'tail -f /var/log/'.$location.'/'.$config->base_url.'-'.$log.'.log'; |
|
| 65 | ||
| 66 | return $command; |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param $server |
|
| 71 | * @param $os |
|
| 72 | * |
|
| 73 | * @return string |
|
| 74 | */ |
|
| 75 | private function getLogLocation($server, $os) |
|
| 76 | { |
|
| 77 | $location = 'nginx'; |
|
| 78 | if ($server != 'nginx') { |
|
| 79 | $location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; |
|
| 80 | } |
|
| 81 | ||
| 82 | return $location; |
|
| 83 | } |
|
| @@ 15-80 (lines=66) @@ | ||
| 12 | /** |
|
| 13 | * Class ViewCommand. |
|
| 14 | */ |
|
| 15 | class ViewCommand extends Command |
|
| 16 | { |
|
| 17 | protected $_config; |
|
| 18 | protected $_projectPath; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Configure the view command. |
|
| 22 | */ |
|
| 23 | protected function configure() |
|
| 24 | { |
|
| 25 | $this->_projectPath = getcwd(); |
|
| 26 | $this->setName('log:view'); |
|
| 27 | $this->setDescription('View a specific server log'); |
|
| 28 | $this->addArgument('log', InputArgument::REQUIRED, 'access or error'); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @param InputInterface $input |
|
| 33 | * @param OutputInterface $output |
|
| 34 | * |
|
| 35 | * @return ProcessCommand |
|
| 36 | */ |
|
| 37 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 38 | { |
|
| 39 | $log = $input->getArgument('log'); |
|
| 40 | ||
| 41 | $output->writeln('<info>Viewing '.ucwords($log).' Log</info>'); |
|
| 42 | $command = $this->getCommand(new Config($output), $log); |
|
| 43 | if (!$command) { |
|
| 44 | return $output->writeln('<error>Command not available for this application</error>'); |
|
| 45 | } |
|
| 46 | ||
| 47 | $pCommand = "vagrant ssh -c '".$command."'"; |
|
| 48 | ||
| 49 | return new ProcessCommand($pCommand, $this->_projectPath, $output); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param Config $config |
|
| 54 | * @param $log |
|
| 55 | * |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | private function getCommand(Config $config, $log) |
|
| 59 | { |
|
| 60 | $server = $config->_config['magestead']['server']; |
|
| 61 | $os = $config->_config['magestead']['os']; |
|
| 62 | ||
| 63 | $location = $this->getLogLocation($server, $os); |
|
| 64 | $command = 'cat /var/log/'.$location.'/'.$config->base_url.'-'.$log.'.log'; |
|
| 65 | ||
| 66 | return $command; |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param $server |
|
| 71 | * @param $os |
|
| 72 | * |
|
| 73 | * @return string |
|
| 74 | */ |
|
| 75 | private function getLogLocation($server, $os) |
|
| 76 | { |
|
| 77 | $location = 'nginx'; |
|
| 78 | if ($server != 'nginx') { |
|
| 79 | $location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; |
|
| 80 | } |
|
| 81 | ||
| 82 | return $location; |
|
| 83 | } |
|