Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x nginx #25

Open
wants to merge 29 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
86085e6
Finishing up Nginx support. Just copying provision 3.x templates in a…
jonpugh Jan 26, 2018
b3e8deb
Add Provision::fs() for easy access to a filesystem in static functions.
jonpugh Jan 26, 2018
b1acb4f
Work on getting NGINX to work.
jonpugh Jan 26, 2018
294b625
Output stout and sterr to the same file, and return the full output i…
jonpugh Jan 26, 2018
0c17092
Prepare web server config folders and variables for the nginx template.
jonpugh Jan 26, 2018
7c63f50
Adding and changing additional template vars for the vhost.
jonpugh Jan 26, 2018
1a492f5
Merge branch '4.x' of github.com:aegir-project/provision into 4.x-nginx
jonpugh Feb 2, 2018
2e9ee4a
Merge branch '4.x' into 4.x-nginx
jonpugh Feb 5, 2018
9373dce
Put back code, but commented.
jonpugh Feb 5, 2018
aeade2b
Use server_config_path in NGINX Server Config
jonpugh Feb 5, 2018
dd4dc8f
Create the server_config_path before another tasks run.
jonpugh Feb 5, 2018
aa84782
Add vhost include template for NGINX as class SiteCommonConfiguration
jonpugh Feb 5, 2018
3bfcc40
Updating gitignore
jonpugh Feb 5, 2018
e771583
Merge branch '4.x' into 4.x-nginx
jonpugh Feb 5, 2018
4ff8920
Merge branch '4.x' into 4.x-nginx
jonpugh Mar 30, 2018
2485e89
Moving classes.
jonpugh Mar 30, 2018
3a63e2c
Populate dummy variables for aliases, redirection and ssl_redirection…
jonpugh Apr 2, 2018
e4da2d8
Inherit SiteConfigFile from apache, it's 99% the same.
jonpugh Apr 2, 2018
e37832a
Fix vhost to use document_root_full variable.
jonpugh Apr 2, 2018
b210d5a
Adding php_fpm_sock_location as a server property to NGINX service.
jonpugh Apr 2, 2018
b32ceaf
Load command line options from all available service type classes, Se…
jonpugh Apr 2, 2018
8f4bc5c
Throw an exception message when cannot write file, add method for has…
jonpugh Apr 2, 2018
0901594
Check for property, in case it was removed we don't want to throw an …
jonpugh Apr 2, 2018
04a9823
Return php fpm location with "unix:" in front if a sock file is found.
jonpugh Apr 2, 2018
46768a7
Fixing mis-named php_fpm_sock_location option.
jonpugh Apr 2, 2018
a5a8f36
Update vhost_include with "fastcgi_pass" variable: PHP FPM Socket Loc…
jonpugh Apr 2, 2018
bfa22ff
Set an nginx upstream for our configured php-fpm server. Replace dyna…
jonpugh Apr 2, 2018
4b64c20
Move our upstream for phpfpm to server template. Replace all dynamic …
jonpugh Apr 3, 2018
9cffb8c
forgot a trailing ;in nginx config.
jonpugh Apr 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/Provision/Command/ServicesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,25 @@ public static function getCommandOptions() {

// Load all service options
$options = Context::getServiceOptions();

// For each service type...
foreach ($options as $service => $service_name) {

$class = Service::getClassName($service);

// Load option_documentation() into input options.
foreach (Context::getContextTypeOptions() as $type => $type_name) {
$method = "{$type}_options";
foreach ($class::$method() as $option => $description) {
$description = "$type_name $service service: $description";
$inputDefinition[] = new InputOption($option, NULL, InputOption::VALUE_OPTIONAL, $description);
// Load every available service type.
foreach (Context::getServiceTypeOptions($service) as $service_type => $service_name) {
$class = Service::getClassName($service, $service_type);

Provision::getProvision()->getLogger()->debug("Loading options from $class $service_type");

// Load option_documentation() into input options.
foreach (Context::getContextTypeOptions() as $type => $type_name) {
$method = "{$type}_options";
foreach ($class::$method() as $option => $description) {
$description = "$type_name $service $service_name service: $description";
$inputDefinition[] = new InputOption($option, NULL, InputOption::VALUE_OPTIONAL, $description);
}
}
}

}

return $inputDefinition;
Expand Down Expand Up @@ -283,12 +287,12 @@ private function askForServiceProperties($service, $service_type = NULL) {
$property = Provision::newProperty($property);
}

if ($this->context->hasService($service) && $this->context->getService($service)->getProperty($name)) {
if ($this->context->hasService($service) && $this->context->getService($service)->hasProperty($name) && $this->context->getService($service)->getProperty($name)) {
$property->default = $this->context->getService($service)->getProperty($name);
}

// If option does not exist, ask for it.
if (!empty($this->input->getOption($name))) {
if ($this->input->hasOption($name) && !empty($this->input->getOption($name))) {
$properties[$name] = $this->input->getOption($name);
$this->io->comment("Using option {$name}={$properties[$name]}");
}
Expand Down
6 changes: 6 additions & 0 deletions src/Provision/ConfigFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ function __construct($context, $service = NULL, $data = array()) {
* This is a stub to be implemented by subclasses.
*/
function process() {
$this->data = [];

if (!empty($this->context->getProperties())) {
$this->data = $this->context->getProperties();
}

if (isset($this->service) && !empty($this->service->getProperties())) {
$this->data = array_merge($this->data, $this->service->getProperties());
}

// @TODO: Remove legacy code.
// if (is_object($this->store)) {
// $this->data['records'] = array_filter(array_merge($this->store->loaded_records, $this->store->records));
Expand Down
53 changes: 53 additions & 0 deletions src/Provision/Context/ServerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function __construct($name, Provision $provision, array $options = [])
else {
$this->server_config_path = $this->getProperty('server_config_path');
}

$this->fs = new Filesystem();
}

/**
Expand Down Expand Up @@ -115,4 +117,55 @@ public function verify()
$tasks = [];
return $tasks;
}

/**
* Run a shell command on this server.
*
* @param $cmd string The command to run
* @param $dir string The directory to run the command in. Defaults to this server's config path.
* @param $return string What to return. Can be 'output' or 'exit'.
*
* @return string
* @throws \Exception
*/
public function shell_exec($command, $dir = NULL, $return = 'output') {
$cwd = getcwd();
$original_command = $command;

$tmpdir = sys_get_temp_dir() . '/provision';
if (!Provision::fs()->exists($tmpdir)){
Provision::fs()->mkdir($tmpdir);
}

$datestamp = date('c');
$tmp_output_file = tempnam($tmpdir, 'task.' . $datestamp . '.output.');

$effective_wd = $dir? $dir:
$this->getProperty('server_config_path');

if ($this->getProvision()->getOutput()->isVerbose()) {
$this->getProvision()->io()->commandBlock($command, $effective_wd);
}

// Output and Errors to files.
$command .= "> $tmp_output_file 2>&1";

chdir($effective_wd);
exec($command, $output, $exit);
chdir($cwd);

$output = file_get_contents($tmp_output_file);

if (!empty($output)){
if ($this->getProvision()->getOutput()->isVerbose()) {
$this->getProvision()->io()->outputBlock($output);
}
}

if ($exit != ResultData::EXITCODE_OK) {
throw new \Exception($output);
}

return ${$return};
}
}
34 changes: 29 additions & 5 deletions src/Provision/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ protected function writeConfigurations(Context $context = NULL)
);
}
catch (\Exception $e) {
$context->getProvision()->getLogger()->info(
'Unable to write {description} to {path}.', [
'description' => $config->description,
'path' => $config->filename(),
throw new \Exception(strtr(
'Unable to write {description} to {path}: {message}', [
'{description}' => $config->description,
'{path}' => $config->filename(),
'{message}' => $e->getMessage(),
]
);
));
$success = FALSE;
}
}
Expand Down Expand Up @@ -243,6 +244,29 @@ public function getName()
return $this::SERVICE;
}

/**
* Return all properties for this context.
*
* @return array
*/
public function getProperties() {
return $this->properties;
}

/**
* Whether or not this Services has a property.
*
* @param $type
* @return bool
*/
public function hasProperty($name) {
if (isset($this->properties[$name])) {
return TRUE;
}
else {
return FALSE;
}
}

/**
* Get a specific property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function process() {
$extra_apache_configs = $this->getContext()->servicesInvoke('extraApacheConfig', [$this]);
$this->data['extra_config'] = implode("\n", $extra_apache_configs);

$this->data['aliases'] = [];
$this->data['redirection'] = FALSE;
$this->data['ssl_redirection'] = FALSE;

// if ($this->aliases && !is_array($this->aliases)) {
// $this->aliases = explode(",", $this->aliases);
// }
Expand Down
Loading