Commit e1e0d969 authored by Jon Pugh's avatar Jon Pugh

Merge branch '4.x-robo-collections-verify' of...

Merge branch '4.x-robo-collections-verify' of github.com:aegir-project/provision into 4.x-robo-collections-verify
parents 7b40c7bb 74f978db
......@@ -232,7 +232,7 @@ class Configuration {
* 5. Render template with $this and $data and write out to filename().
* 6. If $mode and/or $group are set, apply them for the new file.
*/
function write() {
function write(Service $service) {
// Make directory structure if it does not exist.
$filename = $this->filename();
......@@ -249,6 +249,7 @@ class Configuration {
if ($filename && is_writeable(dirname($filename))) {
// manipulate data before passing to template.
$this->process();
$service->processConfiguration($this);
if ($template = $this->load_template()) {
// Make sure we can write to the file
......
......@@ -497,8 +497,10 @@ class Context implements BuilderAwareInterface
$collection->addCode(function() use ($friendlyName, $type) {
$this->getProvision()->io()->section("Verify service: {$friendlyName}");
}, 'logging.' . $type);
$service->setContext($this);
$tasks = $service->verify();
foreach ($tasks as $title => $task) {
$collection->getConfig()->set('success', '');
$collection->getConfig()->set('failure', '');
......
......@@ -89,8 +89,9 @@ class Service implements BuilderAwareInterface
*/
public function verify() {
$method = 'verify' . ucfirst($this->getContext()->type);
$this->getProvision()->getLogger()->info("Running {method}", [
'method' => $method
$this->getProvision()->getLogger()->info("Running method {method} on class {class}", [
'method' => $method,
'class' => get_class($this),
]);
return $this::$method();
}
......@@ -140,14 +141,17 @@ class Service implements BuilderAwareInterface
}
else {
$task = $this->getProvision()->getTasks()->taskExec($this->getProperty('restart_command'))
->silent(!$this->getProvision()->io()->isVerbose())
->silent(!$this->getProvision()->getOutput()->isVerbose())
;
/** @var \Robo\Result $result */
$result = $task->run();
if (!$result->wasSuccessful()) {
throw new \Exception('Unable to restart service using command: ' . $this->getProperty('restart_command'));
}
else {
return TRUE;
}
}
}
......@@ -182,7 +186,7 @@ class Service implements BuilderAwareInterface
{
// If we are writing for a serviceSubscription, use the provider context.
if ($serviceSubscription) {
$context = $serviceSubscription->context;
$context = $serviceSubscription->getContext();
}
else {
$context = $this->provider;
......@@ -196,15 +200,21 @@ class Service implements BuilderAwareInterface
foreach ($this->getConfigurations()[$context->type] as $configuration_class) {
try {
$config = new $configuration_class($context, $this);
$config->write();
// $context->getProvision()->io()->successLite(
// 'Wrote '.$config->description.' to '.$config->filename()
// );
$config->write($this);
$context->getProvision()->getLogger()->info(
'Wrote {description} to {path}.', [
'description' => $config->description,
'path' => $config->filename(),
]
);
}
catch (\Exception $e) {
// $context->getProvision()->io()->errorLite(
// 'Unable to write '.$config->description.' to '.$config->filename() . ': ' . $e->getMessage()
// );
$context->getProvision()->getLogger()->info(
'Unable to write {description} to {path}.', [
'description' => $config->description,
'path' => $config->filename(),
]
);
$success = FALSE;
}
}
......
......@@ -10,6 +10,7 @@ namespace Aegir\Provision\Service;
//require_once DRUSH_BASE_PATH . '/commands/core/rsync.core.inc';
use Aegir\Provision\Context;
use Aegir\Provision\Context\SiteContext;
use Aegir\Provision\Service;
use Aegir\Provision\ServiceInterface;
......@@ -26,6 +27,7 @@ class DbService extends Service implements ServiceInterface
{
const SERVICE = 'db';
const SERVICE_TYPE = NULL;
const SERVICE_NAME = 'Database Server';
......@@ -50,7 +52,33 @@ class DbService extends Service implements ServiceInterface
* Indicates the place holders that should be replaced in _db_query_callback().
*/
const PROVISION_QUERY_REGEXP = '/(%d|%s|%%|%f|%b)/';
/**
* DbService constructor.
*
* Set dsn based on context's service config.
*
* @param $service_config
* @param Context $provider_context
*/
function __construct($service_config, Context $provider_context)
{
parent::__construct($service_config, $provider_context);
$this->creds = array_map('urldecode', parse_url($this->properties['master_db']));
if (!isset($this->creds['port'])) {
$this->creds['port'] = '3306';
}
if (!isset($this->creds['pass'])) {
$this->creds['pass'] = '';
}
$this->dsn = sprintf("%s:host=%s;port=%s", $this::SERVICE_TYPE, $this->creds['host'], $this->creds['port']);
}
/**
* Implements Service::server_options()
*
......@@ -92,18 +120,6 @@ class DbService extends Service implements ServiceInterface
* React to the `provision verify` command on Server contexts
*/
function verifyServer() {
$this->creds = array_map('urldecode', parse_url($this->properties['master_db']));
if (!isset($this->creds['port'])) {
$this->creds['port'] = '3306';
}
if (!isset($this->creds['pass'])) {
$this->creds['pass'] = '';
}
$this->dsn = sprintf("%s:host=%s;port=%s", $this::SERVICE_TYPE, $this->creds['host'], $this->creds['port']);
$tasks = [];
// Confirm we can connect to the database server as root.
......@@ -169,7 +185,11 @@ class DbService extends Service implements ServiceInterface
* React to the `provision verify` command on subscriber contexts (sites and platforms)
*/
function verifySite() {
$this->subscription = $this->getContext()->getSubscription($this->type);
return [
'Prepared site database.' => function () {
$this->subscription = $this->getContext()->getSubscription($this::SERVICE);
// Check for database
$this->create_site_database($this->getContext());
......@@ -189,34 +209,21 @@ class DbService extends Service implements ServiceInterface
try {
$this->connect();
$this->subscription->context->getProvision()->io()->successLite('Successfully connected to database server.');
return [
'service' => TRUE
];
$this->subscription->getContext()->getProvision()->io()->successLite('Successfully connected to database server.');
}
catch (\PDOException $e) {
$this->subscription->context->getProvision()->io()->errorLite($e->getMessage());
return [
'service' => FALSE
];
throw new \Exception('Unable to connect to database using service properties: ' . $e->getMessage());
}
}
];
}
public function verifyPlatform() {
}
/**
* React to `provision verify` command when run on a subscriber, to verify the service's provider.
*
* This is used to verify the database server when a subscriber is verified.
*/
function verifyProvider()
{
return [
'service' => $this->verify(),
];
}
/**
* Attempt to connect to the database server using $this->creds
......
......@@ -28,7 +28,7 @@ class SiteConfiguration extends Configuration {
function process() {
parent::process();
$this->data['http_port'] = $this->context->platform->getSubscription('http')->service->getProperty('http_port');
$this->data['http_port'] = $this->context->getSubscription('http')->service->getProperty('http_port');
$this->data['root'] = $this->context->platform->getProperty('root');
$this->data['uri'] = $this->context->getProperty('uri');
......
<Directory <?php print $this->context->config['root']; ?>>
<Directory <?php print $root; ?>>
Order allow,deny
Allow from all
Satisfy any
......@@ -8,9 +8,9 @@
<?php
if (is_readable("{$this->context->config['root']}/.htaccess")) {
if (is_readable("{$root}/.htaccess")) {
print "\n# Include the platform's htaccess file\n";
print "Include {$this->context->config['root']}/.htaccess\n";
print "Include {$root}/.htaccess\n";
}
?>
......
......@@ -52,8 +52,8 @@ RUN chmod 0440 /etc/sudoers.d/aegir
# Prepare Aegir Logs folder.
RUN mkdir /var/log/aegir
RUN chown aegir:aegir /var/log/aegir
RUN echo 'Hello, Aegir.' > /var/log/aegir/system.log
RUN chown aegir:aegir /var/log/aegir -R
# Prepare apache foreground script.
COPY httpd-foreground.sh /usr/local/bin/httpd-foreground
......
#!/bin/bash
echo "𝙋𝙍𝙊 ║ Started httpd-foreground.sh ..."
# Copied from official httpd container: https://github.com/docker-library/httpd/blob/fa5223d83a5225aa3fd5b23229b785c7764142bf/2.2/httpd-foreground
......@@ -9,6 +10,12 @@ set -e
#source /etc/apache2/envvars
#exec apache2 -DFOREGROUND
echo "𝙋𝙍𝙊 ║ Checking folder /etc/apache2/conf-available"
ls -la /etc/apache2/conf-available
echo "𝙋𝙍𝙊 ║ Checking folder /etc/apache2/conf-enabled"
ls -la /etc/apache2/conf-enabled
# Add symlink from our server's config to the apache include target.
echo "𝙋𝙍𝙊 ║ Checking folder $AEGIR_ROOT/config"
ls -la $AEGIR_ROOT/config/
......@@ -17,8 +24,8 @@ echo "𝙋𝙍𝙊 ║ Checking folder $AEGIR_ROOT/config/$AEGIR_SERVER_NAME:"
ls -la $AEGIR_ROOT/config/$AEGIR_SERVER_NAME
# If there are no platforms assigned to the server, docker.conf and the docker config folders are never created.
#if [ ! -f '$AEGIR_ROOT/config/$AEGIR_SERVER_NAME/docker.conf' ]; then
# touch $AEGIR_ROOT/config/$AEGIR_SERVER_NAME/docker.conf
#if [ ! -f '$AEGIR_ROOT/config/$AEGIR_SERVER_NAME/apacheDocker.conf' ]; then
# touch $AEGIR_ROOT/config/$AEGIR_SERVER_NAME/apacheDocker.conf
#fi
#
......@@ -28,8 +35,5 @@ ln -sf $AEGIR_ROOT/config/$AEGIR_SERVER_NAME/apacheDocker.conf $AEGIR_ROOT/confi
echo "𝙋𝙍𝙊 ║ Running sudo /usr/sbin/apache2ctl start"
sudo /usr/sbin/apache2ctl start
echo "𝙋𝙍𝙊 ║ Running sudo /usr/sbin/apache2ctl start"
sudo /usr/sbin/apache2ctl start
echo "𝙋𝙍𝙊 ║ Running tail -f /var/log/aegir/system.log"
tail -f /var/log/aegir/system.log
\ No newline at end of file
......@@ -64,7 +64,7 @@ class HttpService extends Service implements ServiceInterface {
return [
'http.configuration' => $this->getProvision()->newTask()
->execute(function() {
$this->writeConfigurations();
return $this->writeConfigurations()? 0: 1;
})
->success('Wrote web server configuration files.')
->failure('Unable to write config files for this service.'),
......@@ -82,14 +82,38 @@ class HttpService extends Service implements ServiceInterface {
* React to the `provision verify` command on Server contexts
*/
function verifySite() {
$this->subscription = $this->getContext()->getSubscription();
return [
'configuration' => $this->writeConfigurations($this->subscription),
'service' => $this->restartService(),
];
$this->subscription = $this->getContext()->getSubscription('http');
$tasks = [];
$tasks['http.site.configuration'] = $this->getProvision()->newTask()
->success('Wrote site configuration files.')
->failure('Unable to write site configuration files.')
->execute(function () {
return $this->writeConfigurations($this->subscription)? 0: 1;
})
;
$tasks['http.site.service'] = $this->getProvision()->newTask()
->success('Restarted web server.')
->failure('Unable to restart web service.')
->execute(function () {
return $this->restartService()? 0: 1;
})
;
return $tasks;
}
function verifyPlatform() {
$tasks = [];
$tasks['http.platform.configuration'] = $this->getProvision()->newTask()
->success('Wrote platform configuration to ...')
->failure('Unable to write platform configuration file.')
->execute(function () {
$this->writeConfigurations($this->getContext()->getSubscription('http'));
})
;
$tasks = array_merge($tasks, $this->verifyServer());
return $tasks;
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment