Skip to content
Commits on Source (10)
...@@ -124,7 +124,7 @@ class Application extends BaseApplication ...@@ -124,7 +124,7 @@ class Application extends BaseApplication
$commands[] = new ListCommand(); $commands[] = new ListCommand();
$commands[] = new SaveCommand(); $commands[] = new SaveCommand();
$commands[] = new ServicesCommand(); $commands[] = new ServicesCommand();
$commands[] = new ShellCommand(); // $commands[] = new ShellCommand();
$commands[] = new StatusCommand(); $commands[] = new StatusCommand();
$commands[] = new VerifyCommand(); $commands[] = new VerifyCommand();
...@@ -165,7 +165,7 @@ class Application extends BaseApplication ...@@ -165,7 +165,7 @@ class Application extends BaseApplication
$class = '\Aegir\Provision\Context\\' . ucfirst($context_type) . "Context"; $class = '\Aegir\Provision\Context\\' . ucfirst($context_type) . "Context";
$contexts[$context_name] = new $class($context_name, $this->config->all(), $this); $contexts[$context_name] = new $class($context_name, $this->config->all(), $this);
} }
if ($name) { if ($name) {
return $contexts[$name]; return $contexts[$name];
} }
...@@ -220,11 +220,11 @@ class Application extends BaseApplication ...@@ -220,11 +220,11 @@ class Application extends BaseApplication
public function getServerOptions($service_type = '') { public function getServerOptions($service_type = '') {
$servers = []; $servers = [];
foreach ($this->getAllServers() as $server) { foreach ($this->getAllServers() as $server) {
if ($service_type && isset($server->services[$service_type])) { if ($service_type && !empty($server->config['services'][$service_type])) {
$servers[$server->name] = $server->name . ': ' . $server->getService($service_type)->type; $servers[$server->name] = $server->name . ': ' . $server->config['services'][$service_type]['type'];
} }
else { elseif ($service_type == '') {
$servers[$server->name] = $server->name . ': ' . $server->getService($service_type)->type; $servers[$server->name] = $server->name . ': ' . $server->config['services'][$service_type]['type'];
} }
} }
return $servers; return $servers;
......
...@@ -8,6 +8,7 @@ use Aegir\Provision\Context\PlatformContext; ...@@ -8,6 +8,7 @@ use Aegir\Provision\Context\PlatformContext;
use Aegir\Provision\Context\ServerContext; use Aegir\Provision\Context\ServerContext;
use Aegir\Provision\Context\SiteContext; use Aegir\Provision\Context\SiteContext;
use Consolidation\AnnotatedCommand\CommandFileDiscovery; use Consolidation\AnnotatedCommand\CommandFileDiscovery;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
...@@ -123,6 +124,10 @@ class ServicesCommand extends Command ...@@ -123,6 +124,10 @@ class ServicesCommand extends Command
// If server, ask which service type. // If server, ask which service type.
if ($this->context->type == 'server') { if ($this->context->type == 'server') {
if (empty($this->context->getServiceTypeOptions($service))) {
throw new \Exception("There was no class found for service $service. Create one named \\Aegir\\Provision\\Service\\{$service}Service");
}
$service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service)); $service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
// Then ask for all options. // Then ask for all options.
...@@ -137,6 +142,10 @@ class ServicesCommand extends Command ...@@ -137,6 +142,10 @@ class ServicesCommand extends Command
} }
// All other context types are associating with servers that provide the service. // All other context types are associating with servers that provide the service.
else { else {
if (empty($this->getApplication()->getServerOptions($service))) {
throw new \Exception("No servers providing $service service were found. Create one with `provision save` or use `provision services` to add to an existing server.");
}
$server = $this->io->choice('Which server?', $this->getApplication()->getServerOptions($service)); $server = $this->io->choice('Which server?', $this->getApplication()->getServerOptions($service));
// Then ask for all options. // Then ask for all options.
......
...@@ -133,6 +133,12 @@ class Context ...@@ -133,6 +133,12 @@ class Context
$this->services[strtolower($service_name)] = new $service_class($service, $this); $this->services[strtolower($service_name)] = new $service_class($service, $this);
} }
} }
elseif (isset($this->config['service_subscriptions'])) {
foreach ($this->config['service_subscriptions'] as $service_name => $service) {
$this->servers[$service_name] = $server = $this->application->getContext($service['server']);
$this->services[$service_name] = new ServiceSubscription($this, $server, $service_name);
}
}
else { else {
$this->services = []; $this->services = [];
} }
...@@ -151,7 +157,10 @@ class Context ...@@ -151,7 +157,10 @@ class Context
$discovery->setSearchPattern('*Service.php'); $discovery->setSearchPattern('*Service.php');
$servicesFiles = $discovery->discover(__DIR__ .'/Service', '\Aegir\Provision\Service'); $servicesFiles = $discovery->discover(__DIR__ .'/Service', '\Aegir\Provision\Service');
foreach ($servicesFiles as $serviceClass) { foreach ($servicesFiles as $serviceClass) {
$classes[$serviceClass::SERVICE] = $serviceClass; // If this is a server, show all services. If it is not, but service allows this type of context, load it.
if ($this->type == 'server' || in_array($this->type, $serviceClass::allowedContexts())) {
$classes[$serviceClass::SERVICE] = $serviceClass;
}
} }
if ($service && isset($classes[$service])) { if ($service && isset($classes[$service])) {
...@@ -334,9 +343,24 @@ class Context ...@@ -334,9 +343,24 @@ class Context
*/ */
public function showServices(DrupalStyle $io) { public function showServices(DrupalStyle $io) {
if (!empty($this->getServices())) { if (!empty($this->getServices())) {
$is_server = $this->type == 'server';
$rows = []; $rows = [];
$headers = $is_server?
['Services']:
['Service', 'Server', 'Type'];
foreach ($this->getServices() as $name => $service) { foreach ($this->getServices() as $name => $service) {
$rows[] = [$name, $service->type]; if ($is_server) {
$rows[] = [$name, $service->type];
}
else {
$rows[] = [
$name,
$service->server->name,
$service->server->getService($name)->type
];
}
// Show all properties. // Show all properties.
if (!empty($service->properties )) { if (!empty($service->properties )) {
...@@ -345,7 +369,7 @@ class Context ...@@ -345,7 +369,7 @@ class Context
} }
} }
} }
$io->table(['Services'], $rows); $io->table($headers, $rows);
} }
} }
...@@ -413,7 +437,23 @@ class Context ...@@ -413,7 +437,23 @@ class Context
return '\Aegir\Provision\Context\\' . ucfirst($type) . "Context"; return '\Aegir\Provision\Context\\' . ucfirst($type) . "Context";
} }
// public function verify() {
// return "Provision Context";
// }
/**
* Verify this context.
*
* Running `provision verify CONTEXT` triggers this method.
*
* Collect all services for the context and run the verify() method on them
*/
public function verify() { public function verify() {
return "Provision Context";
// Run verify method on all services.
foreach ($this->getServices() as $service) {
$service->verify();
}
} }
} }
...@@ -4,6 +4,7 @@ namespace Aegir\Provision\Context; ...@@ -4,6 +4,7 @@ namespace Aegir\Provision\Context;
use Aegir\Provision\Application; use Aegir\Provision\Application;
use Aegir\Provision\Context; use Aegir\Provision\Context;
use Aegir\Provision\Service\Http\Apache\Configuration\PlatformConfiguration;
use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\ConfigurationInterface;
/** /**
...@@ -61,10 +62,10 @@ class PlatformContext extends Context implements ConfigurationInterface ...@@ -61,10 +62,10 @@ class PlatformContext extends Context implements ConfigurationInterface
return $options; return $options;
} }
// @TODO: Remove. This should be handled by Services now.
public function verify() { // public function verify() {
parent::verify(); // parent::verify();
$this->web_server->verify(); // $this->logger->info('Verifying Web Server...');
return "Platform Context Verified: " . $this->name; // $this->web_server->verify();
} // }
} }
...@@ -36,14 +36,4 @@ class ServerContext extends Context implements ConfigurationInterface ...@@ -36,14 +36,4 @@ class ServerContext extends Context implements ConfigurationInterface
return $options; return $options;
} }
public function verify() {
// Run verify method on all services.
foreach ($this->getServices() as $service) {
$service->verify();
}
return "Server Context Verified: " . $this->name;
}
} }
...@@ -33,15 +33,18 @@ class SiteContext extends Context implements ConfigurationInterface ...@@ -33,15 +33,18 @@ class SiteContext extends Context implements ConfigurationInterface
parent::__construct($name, $console_config, $application, $options); parent::__construct($name, $console_config, $application, $options);
// Load "db_server" context. // Load "db_server" context.
if (isset($this->config['db_server'])) { // if (isset($this->config['service_subscriptions']['db'])) {
$this->db_server = $application->getContext($this->config['service_subscriptions']['db']['server']); // $this->db_server = $application->getContext($this->config['service_subscriptions']['db']['server']);
$this->db_server->logger = $application->logger; // }
$this->platform = $application->getContext($this->config['platform']); $this->logger = $application->logger;
}
else { if (isset($this->config['platform'])) {
throw new \Exception('No db_server found.'); $this->platform = $application->getContext(
$this->config['platform']
);
} }
} }
static function option_documentation() static function option_documentation()
...@@ -63,12 +66,11 @@ class SiteContext extends Context implements ConfigurationInterface ...@@ -63,12 +66,11 @@ class SiteContext extends Context implements ConfigurationInterface
public function verify() { public function verify() {
parent::verify(); parent::verify();
$this->db_server->verify();
$this->platform->verify();
// @TODO: Write VHOST! // $this->db_server->service('db')->verify();
// $this->platform->verify();
return "Site Context Verified: " . $this->name; // return "Site Context Verified: " . $this->name;
} }
// /** // /**
......
...@@ -27,6 +27,14 @@ class Service { ...@@ -27,6 +27,14 @@ class Service {
function verify() { function verify() {
$this->writeConfigurations(); $this->writeConfigurations();
} }
/**
* List context types that are allowed to subscribe to this service.
* @return array
*/
static function allowedContexts() {
return [];
}
/** /**
* Write this service's configurations. * Write this service's configurations.
...@@ -35,6 +43,7 @@ class Service { ...@@ -35,6 +43,7 @@ class Service {
if (empty($this->getConfigurations()[$this->context->type])) { if (empty($this->getConfigurations()[$this->context->type])) {
return; return;
} }
$this->context->application->logger->info('CONTEXT ' . $this->context->type);
foreach ($this->getConfigurations()[$this->context->type] as $configuration_class) { foreach ($this->getConfigurations()[$this->context->type] as $configuration_class) {
$config = new $configuration_class($this->context, $this); $config = new $configuration_class($this->context, $this);
$config->write(); $config->write();
......
...@@ -36,7 +36,17 @@ class DbService extends Service ...@@ -36,7 +36,17 @@ class DbService extends Service
'db_grant_all_hosts' => 'Grant access to site database users from any web host. If set to TRUE, any host will be allowed to connect to MySQL site databases on this server using the generated username and password. If set to FALSE, web hosts will be granted access by their detected IP address.', 'db_grant_all_hosts' => 'Grant access to site database users from any web host. If set to TRUE, any host will be allowed to connect to MySQL site databases on this server using the generated username and password. If set to FALSE, web hosts will be granted access by their detected IP address.',
]; ];
} }
/**
* List context types that are allowed to subscribe to this service.
* @return array
*/
static function allowedContexts() {
return [
'site'
];
}
/** /**
* Implements Service::server_options() * Implements Service::server_options()
* *
......
...@@ -22,12 +22,18 @@ class SiteConfiguration extends Configuration { ...@@ -22,12 +22,18 @@ class SiteConfiguration extends Configuration {
function filename() { function filename() {
if (drush_get_option('provision_apache_conf_suffix', FALSE)) { $file = $this->uri . '.conf';
return $this->data['http_vhostd_path'] . '/' . $this->uri . '.conf';
} // return $this->service->properties['http_platformd_path'] . '/' . ltrim($this->context->name, '@') . '.conf';
else { return $this->context->console_config['config_path'] . '/' . $this->context->name . '/' . $file;
return $this->data['http_vhostd_path'] . '/' . $this->uri;
} // return $this->context->config['config_path'];
// if (drush_get_option('provision_apache_conf_suffix', FALSE)) {
// return $this->data['http_vhostd_path'] . '/' . $this->uri . '.conf';
// }
// else {
// return $this->data['http_vhostd_path'] . '/' . $this->uri;
// }
} }
function process() { function process() {
...@@ -49,5 +55,16 @@ class SiteConfiguration extends Configuration { ...@@ -49,5 +55,16 @@ class SiteConfiguration extends Configuration {
$this->template = $this->disabled_template; $this->template = $this->disabled_template;
} }
$app_dir = $this->context->console_config['config_path'] . '/' . $this->service->getType();
// $this->data['http_port'] = $this->service->properties['http_port'];
// $this->data['include_statement'] = '# INCLUDE STATEMENT';
// $this->data['http_pred_path'] = "{$app_dir}/pre.d";
// $this->data['http_postd_path'] = "{$app_dir}/post.d";
// $this->data['http_platformd_path'] = "{$app_dir}/platform.d";
// $this->data['extra_config'] = "";
$this->data['http_vhostd_path'] = "{$app_dir}/vhost.d";
} }
} }
\ No newline at end of file
...@@ -40,6 +40,16 @@ class HttpService extends Service { ...@@ -40,6 +40,16 @@ class HttpService extends Service {
'restart_command' => 'The command to reload the web server configuration;' 'restart_command' => 'The command to reload the web server configuration;'
]; ];
} }
/**
* List context types that are allowed to subscribe to this service.
* @return array
*/
static function allowedContexts() {
return [
'platform'
];
}
/** /**
* Support the ability to cloak the database credentials using environment variables. * Support the ability to cloak the database credentials using environment variables.
......
<?php
/**
* @file
* A context's subscription to a service. Handles properties specific to a
* context for each service.
*
* @see Provision_Service
*/
namespace Aegir\Provision;
class ServiceSubscription {
public $context;
public $service;
public $server;
public $type;
function __construct($context, $server, $service_name) {
$this->context = $context;
$this->server = $server;
$this->service = $server->getService($service_name);
$this->type = $server->getService($service_name)->type;
}
}