-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from richdynamix/release/2.1
release/2.1
- Loading branch information
Showing
11 changed files
with
260 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php namespace Magestead\Command\Log; | ||
|
||
use Magestead\Command\ProcessCommand; | ||
use Magestead\Helper\Config; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class StreamCommand | ||
* @package Magestead\Command\Redis | ||
*/ | ||
class StreamCommand extends Command | ||
{ | ||
protected $_config; | ||
protected $_projectPath; | ||
|
||
/** | ||
* Configure the stream command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->_projectPath = getcwd(); | ||
$this->setName("log:stream"); | ||
$this->setDescription("Stream a specific server log"); | ||
$this->addArgument('log', InputArgument::REQUIRED, 'access or error'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return ProcessCommand | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$log = $input->getArgument('log'); | ||
|
||
$output->writeln('<info>Streaming '. ucwords($log) . ' Log</info>'); | ||
$command = $this->getCommand(new Config($output), $log); | ||
if (!$command) { | ||
return $output->writeln('<error>Command not available for this application</error>'); | ||
} | ||
|
||
$pCommand = "vagrant ssh -c '". $command ."'"; | ||
return new ProcessCommand($pCommand, $this->_projectPath, $output); | ||
} | ||
|
||
/** | ||
* @param Config $config | ||
* @param $log | ||
* @return string | ||
*/ | ||
private function getCommand(Config $config, $log) | ||
{ | ||
$server = $config->_config['magestead']['server']; | ||
$os = $config->_config['magestead']['os']; | ||
|
||
$location = $this->getLogLocation($server, $os); | ||
$command = 'tail -f /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log'; | ||
|
||
return $command; | ||
} | ||
|
||
/** | ||
* @param $server | ||
* @param $os | ||
* @return string | ||
*/ | ||
private function getLogLocation($server, $os) | ||
{ | ||
$location = 'nginx'; | ||
if ($server != 'nginx') { | ||
$location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; | ||
} | ||
|
||
return $location; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php namespace Magestead\Command\Log; | ||
|
||
use Magestead\Command\ProcessCommand; | ||
use Magestead\Helper\Config; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class ViewCommand | ||
* @package Magestead\Command\Redis | ||
*/ | ||
class ViewCommand extends Command | ||
{ | ||
protected $_config; | ||
protected $_projectPath; | ||
|
||
/** | ||
* Configure the view command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->_projectPath = getcwd(); | ||
$this->setName("log:view"); | ||
$this->setDescription("View a specific server log"); | ||
$this->addArgument('log', InputArgument::REQUIRED, 'access or error'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return ProcessCommand | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$log = $input->getArgument('log'); | ||
|
||
$output->writeln('<info>Viewing '. ucwords($log) . ' Log</info>'); | ||
$command = $this->getCommand(new Config($output), $log); | ||
if (!$command) { | ||
return $output->writeln('<error>Command not available for this application</error>'); | ||
} | ||
|
||
$pCommand = "vagrant ssh -c '". $command ."'"; | ||
return new ProcessCommand($pCommand, $this->_projectPath, $output); | ||
} | ||
|
||
/** | ||
* @param Config $config | ||
* @param $log | ||
* @return string | ||
*/ | ||
private function getCommand(Config $config, $log) | ||
{ | ||
$server = $config->_config['magestead']['server']; | ||
$os = $config->_config['magestead']['os']; | ||
|
||
$location = $this->getLogLocation($server, $os); | ||
$command = 'cat /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log'; | ||
|
||
return $command; | ||
} | ||
|
||
/** | ||
* @param $server | ||
* @param $os | ||
* @return string | ||
*/ | ||
private function getLogLocation($server, $os) | ||
{ | ||
$location = 'nginx'; | ||
if ($server != 'nginx') { | ||
$location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; | ||
} | ||
|
||
return $location; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php namespace Magestead\Service; | ||
|
||
/** | ||
* Class UsageApi | ||
* @package Magestead\Service | ||
*/ | ||
class UsageApi | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $_apiUrl = "http://api.magestead.com/v1/usage"; | ||
// protected $_apiUrl = "http://magestead-api.app/v1/usage"; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_params = []; | ||
|
||
/** | ||
* UsageApi constructor. | ||
* @param $data | ||
*/ | ||
public function __construct($data) | ||
{ | ||
$this->_params['os_type'] = urlencode($data['os']); | ||
$this->_params['server_type'] = urlencode($data['server']); | ||
$this->_params['php_version'] = urlencode($data['phpver']); | ||
$this->_params['application_version'] = urlencode($data['app']); | ||
$this->_params['vm_memory_limit'] = urlencode($data['memory_limit']); | ||
$this->_params['vm_cpu_count'] = urlencode($data['cpus']); | ||
$this->_params['ip_address'] = urlencode($data['ip_address']); | ||
$this->_params['box'] = urlencode($data['box']); | ||
$this->_params['locale'] = urlencode($data['locale']); | ||
$this->_params['default_currency'] = urlencode($data['default_currency']); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function send() | ||
{ | ||
$fields_string = $this->getFieldsString(); | ||
|
||
$ch = curl_init(); | ||
|
||
curl_setopt($ch,CURLOPT_URL, $this->_apiUrl); | ||
curl_setopt($ch,CURLOPT_POST, count($this->_params)); | ||
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
$result = curl_exec($ch); | ||
|
||
curl_close($ch); | ||
|
||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getFieldsString() | ||
{ | ||
$fields_string = ''; | ||
foreach ($this->_params as $key => $value) { | ||
$fields_string .= $key . '=' . $value . '&'; | ||
} | ||
rtrim($fields_string, '&'); | ||
return $fields_string; | ||
} | ||
} |