diff --git a/src/Application.php b/src/Application.php index 16513a3f860584aab762fdf82abe8ecb8a7d1d7f..6aab5af8af94022cbe88abedd0b32153ee3d42d1 100644 --- a/src/Application.php +++ b/src/Application.php @@ -73,6 +73,17 @@ class Application extends BaseApplication parent::__construct($name, $version); } + /** + * Make configureIO public so we can run it before ->run() + * + * @param InputInterface $input + * @param OutputInterface $output + */ + public function configureIO(InputInterface $input, OutputInterface $output) + { + parent::configureIO($input, $output); + } + /** * Initializes all the default commands. */ diff --git a/src/Command/VerifyCommand.php b/src/Command/VerifyCommand.php index db5e7304cbcac6fba34f397df1eaf41ad52073d7..786b53ed77df086c615a92b44d34b21a16409db8 100644 --- a/src/Command/VerifyCommand.php +++ b/src/Command/VerifyCommand.php @@ -75,7 +75,7 @@ class VerifyCommand extends Command } */ - $message = $this->context->verify(); + $message = $this->context->verifyCommand(); } } diff --git a/src/Common/ContextAwareTrait.php b/src/Common/ContextAwareTrait.php index 6513a2a8a2e9a0319d438fa48532eb39f380bc64..21089e730c9633c5c7695a410a60cf9a81d5b63d 100644 --- a/src/Common/ContextAwareTrait.php +++ b/src/Common/ContextAwareTrait.php @@ -2,7 +2,6 @@ namespace Aegir\Provision\Common; -use Aegir\Provision; use Aegir\Provision\Context; trait ContextAwareTrait @@ -29,11 +28,6 @@ trait ContextAwareTrait */ public function getContext() { - - if (is_null($this->context)) { - return Provision::getContext()(); - } - return $this->context; } } diff --git a/src/Context.php b/src/Context.php index d623fe2c28f6d75aec14a1636852aa18d9d603c4..2950d7463dbd69bbb3b26e106ca9689623b10006 100644 --- a/src/Context.php +++ b/src/Context.php @@ -468,32 +468,33 @@ class Context implements BuilderAwareInterface * * If this context is a Service Subscriber, the provider service will be verified first. */ - public function verify() { + public function verifyCommand() { $return_codes = []; // Run verify method on all services. foreach ($this->getServices() as $type => $service) { - $friendlyName = $service->getFriendlyName(); - - if ($this->isProvider()) { - $this->getProvision()->io()->section("Verify service: {$friendlyName}"); - foreach ($service->verify() as $type => $verify_success) { - $return_codes[] = $verify_success? 0: 1; - } - } - else { - $this->getProvision()->io()->section("Verify service: {$friendlyName} on {$service->provider->name}"); - - // First verify the service provider. - foreach ($service->verifyProvider() as $verify_part => $verify_success) { - $return_codes[] = $verify_success? 0: 1; - } - - // Then run "verify" on the subscriptions. - foreach ($this->getSubscription($type)->verify() as $type => $verify_success) { - $return_codes[] = $verify_success? 0: 1; - } - } + $return_codes[] = $service->verify() ? 0 : 1; } +// +// if ($this->isProvider()) { +// $this->getProvision()->io()->section("Verify service: {$friendlyName}"); +// foreach ($service->verify() as $type => $verify_success) { +// $return_codes[] = $verify_success? 0: 1; +// } +// } +// else { +// $this->getProvision()->io()->section("Verify service: {$friendlyName} on {$service->provider->name}"); +// +// // First verify the service provider. +// foreach ($service->verifyProvider() as $verify_part => $verify_success) { +// $return_codes[] = $verify_success? 0: 1; +// } +// +// // Then run "verify" on the subscriptions. +// foreach ($this->getSubscription($type)->verify() as $type => $verify_success) { +// $return_codes[] = $verify_success? 0: 1; +// } +// } +// } // If any service verify failed, exit with a non-zero code. if (count(array_filter($return_codes))) { diff --git a/src/Provision.php b/src/Provision.php index 69482499a922161c1dc73263db53ad0970cf438e..4519aef9c32d97f2809b95c58ae1a778b3bbadd2 100644 --- a/src/Provision.php +++ b/src/Provision.php @@ -79,16 +79,18 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger $this ->setConfig($config) - ->setInput($input) - ->setOutput($output) ; - + // Create Application. $application = new Application(self::APPLICATION_NAME, self::VERSION); $application ->setProvision($this) - ->setLogger($logger); - + ->setLogger($logger) + ; + $application->configureIO($input, $output); + $this->setInput($input); + $this->setOutput($output); + // Create and configure container. $container = Robo::createDefaultContainer($input, $output, $application, $config); $this->setContainer($container); @@ -108,7 +110,7 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger public function run(InputInterface $input, OutputInterface $output) { $status_code = $this->runner->run($input, $output); - + return $status_code; } diff --git a/src/Service.php b/src/Service.php index 2b6bbeacf3678e071f3d8a22d9ced02742ba4545..353200c8b4f34a0c6ce852926b6ccaad90d9a7c5 100644 --- a/src/Service.php +++ b/src/Service.php @@ -8,17 +8,20 @@ namespace Aegir\Provision; +use Aegir\Provision\Common\ContextAwareTrait; use Aegir\Provision\Common\ProvisionAwareTrait; +use Psr\Log\LoggerAwareTrait; use Robo\Common\BuilderAwareTrait; use Robo\Common\OutputAdapter; use Robo\Contract\BuilderAwareInterface; class Service implements BuilderAwareInterface { - use BuilderAwareTrait; use ProvisionAwareTrait; - + use ContextAwareTrait; + use LoggerAwareTrait; + public $type; public $properties; @@ -46,7 +49,9 @@ class Service implements BuilderAwareInterface function __construct($service_config, Context $provider_context) { $this->provider = $provider_context; + $this->setContext($provider_context); $this->setProvision($provider_context->getProvision()); + $this->setLogger($provider_context->getProvision()->getLogger()); $this->type = $service_config['type']; $this->properties = $service_config['properties']; @@ -77,30 +82,54 @@ class Service implements BuilderAwareInterface return "\Aegir\Provision\Service\\{$service}Service"; } } - - /** - * React to the `provision verify` command. - */ - function verify() - { - return [ - 'configuration' => $this->writeConfigurations(), - 'service' => $this->restartService(), - ]; - } /** - * React to `provision verify` command when run on a subscriber, to verify the service's provider. - * - * This is used to allow skipping of the service restart. + * React to the verify command. Passes off to the method verifySite, verifyServer, verifyPlatform. + * @return mixed */ - function verifyProvider() - { - return [ - 'configuration' => $this->writeConfigurations(), - ]; + public function verify() { + $method = 'verify' . ucfirst($this->getContext()->type); + $this->getProvision()->getLogger()->info("Running {method}", [ + 'method' => $method + ]); + return $this::$method(); } +// +// /** +// * React to the `provision verify` command. +// */ +// function verifySite() +// { +// return [ +// 'configuration' => $this->writeConfigurations(), +// 'service' => $this->restartService(), +// ]; +// } +// +// /** +// * React to the `provision verify` command. +// */ +// function verifyPlatform() +// { +// return [ +// 'configuration' => $this->writeConfigurations(), +// 'service' => $this->restartService(), +// ]; +// } +// +// /** +// * React to `provision verify` command when run on a subscriber, to verify the service's provider. +// * +// * This is used to allow skipping of the service restart. +// */ +// function verifyServer() +// { +// return [ +// 'configuration' => $this->writeConfigurations(), +// ]; +// } + /** * Run the services "restart_command". * @return bool diff --git a/src/Service/DbService.php b/src/Service/DbService.php index 8c9e948c04fa7b9c432c7d5d562ca375b1b5d2b9..188bbf6d78b7e9cce7b8e72dc3ee4f0dd8c3fd95 100644 --- a/src/Service/DbService.php +++ b/src/Service/DbService.php @@ -12,6 +12,7 @@ namespace Aegir\Provision\Service; use Aegir\Provision\Context\SiteContext; use Aegir\Provision\Service; +use Aegir\Provision\ServiceInterface; use Aegir\Provision\ServiceSubscription; use Symfony\Component\Console\Output\OutputInterface; @@ -20,7 +21,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @package Aegir\Provision\Service */ -class DbService extends Service +class DbService extends Service implements ServiceInterface { const SERVICE = 'db'; @@ -89,7 +90,7 @@ class DbService extends Service /** * React to the `provision verify` command on Server contexts */ - function verify() { + function verifyServer() { $this->creds = array_map('urldecode', parse_url($this->properties['master_db'])); if (!isset($this->creds['port'])) { @@ -135,11 +136,11 @@ class DbService extends Service /** * React to the `provision verify` command on subscriber contexts (sites and platforms) */ - function verifySubscription(ServiceSubscription $serviceSubscription) { - $this->subscription = $serviceSubscription; + function verifySite() { + $this->subscription = $this->getContext()->getSubscription($this->type); // Check for database - $this->create_site_database($serviceSubscription->context); + $this->create_site_database($this->getContext()); $this->creds_root = array_map('urldecode', parse_url($this->properties['master_db'])); @@ -169,6 +170,10 @@ class DbService extends Service } } + public function verifyPlatform() { + + } + /** * React to `provision verify` command when run on a subscriber, to verify the service's provider. * diff --git a/src/Service/Http/HttpPhpService.php b/src/Service/Http/HttpPhpService.php new file mode 100644 index 0000000000000000000000000000000000000000..aeae730db653b7fcf94dd97205b73b425f75912a --- /dev/null +++ b/src/Service/Http/HttpPhpService.php @@ -0,0 +1,81 @@ +getContext()->getProperty('remote_host'); + $port = $this->getProperty('http_port'); + + $this->getProvision()->getLogger()->info('Running server at {host}:{port}', [ + 'host' => $host, + 'port' => $port, + ]); +// + + $this->getContext()->getBuilder()->build(PhpServer::class, ['port' => $port]); + +// $server = new PhpServer($port); + + /** @var PhpServer $server */ + $server = $this->getContext()->getBuilder()->task(PhpServer::class, ['port' => $port]); + + $server->host($host); + $server->dir(__DIR__ . '/Php/servertest'); + + $server->background(); + $server->run(); +// + $pid = $server->getProcess()->getPid(); + + $this->getProvision()->getLogger()->info('Server started at {host}:{port} running as process {pid}', [ + 'host' => $host, + 'port' => $port, + 'pid' => $pid, + ]); + + + } + + public function verifySite() + { + } + + public function verifySubscription(ServiceSubscription $subscription) + { + + print_r($subscription->context->getProperty('root')); + $this->application->getBuilder()->taskServer($this->getProperty('http_port')) + ->dir('.');; + + + } +} diff --git a/src/Service/Http/Php/servertest/index.php b/src/Service/Http/Php/servertest/index.php new file mode 100644 index 0000000000000000000000000000000000000000..4c16b1ea30dfaf584236068b9e56c850df2a108e --- /dev/null +++ b/src/Service/Http/Php/servertest/index.php @@ -0,0 +1,5 @@ +

+ +

+ +

diff --git a/src/Service/HttpService.php b/src/Service/HttpService.php index 46f1793e959d3bc3bb5b1eae7a7b5e65822b9750..0afced01a5c10c85bb7bc926dc3c244a6b2bd788 100644 --- a/src/Service/HttpService.php +++ b/src/Service/HttpService.php @@ -11,6 +11,7 @@ namespace Aegir\Provision\Service; //require_once DRUSH_BASE_PATH . '/commands/core/rsync.core.inc'; use Aegir\Provision\Service; +use Aegir\Provision\ServiceInterface; use Aegir\Provision\ServiceSubscription; use Consolidation\AnnotatedCommand\CommandFileDiscovery; @@ -19,7 +20,7 @@ use Consolidation\AnnotatedCommand\CommandFileDiscovery; * * @package Aegir\Provision\Service */ -class HttpService extends Service { +class HttpService extends Service implements ServiceInterface { const SERVICE = 'http'; const SERVICE_NAME = 'Web Server'; @@ -57,7 +58,7 @@ class HttpService extends Service { * * This is used to allow skipping of the service restart. */ - function verifyProvider() + function verifyServer() { return [ 'configuration' => $this->writeConfigurations(), @@ -67,14 +68,18 @@ class HttpService extends Service { /** * React to the `provision verify` command on Server contexts */ - function verifySubscription(ServiceSubscription $serviceSubscription) { - $this->subscription = $serviceSubscription; + function verifySite() { + $this->subscription = $this->getContext()->getSubscription(); return [ - 'configuration' => $this->writeConfigurations($serviceSubscription), + 'configuration' => $this->writeConfigurations($this->subscription), 'service' => $this->restartService(), ]; } -// + + function verifyPlatform() { + } + + // // /** // * Support the ability to cloak the database credentials using environment variables. // */ diff --git a/src/ServiceSubscription.php b/src/ServiceSubscription.php index b7d9932a362a560b965238265c60f24a928bfe54..c2b809a73de2cf3a15ce6d89716db639eeffe2eb 100644 --- a/src/ServiceSubscription.php +++ b/src/ServiceSubscription.php @@ -9,6 +9,7 @@ namespace Aegir\Provision; +use Aegir\Provision\Common\ContextAwareTrait; use Aegir\Provision\Common\ProvisionAwareTrait; class ServiceSubscription { @@ -20,13 +21,14 @@ class ServiceSubscription { public $properties = []; use ProvisionAwareTrait; + use ContextAwareTrait; function __construct( Context $context, $server, $service_name ) { - $this->context = $context; + $this->setContext($context); $this->server = Provision::getContext($server, $context->getProvision()); $this->service = $this->server->getService($service_name); $this->type = $this->server->getService($service_name)->type;