Commit 0bac579e authored by Adrian Rossouw's avatar Adrian Rossouw

Merge remote branch 'origin/dev-services' into dev-envobject

Conflicts:
	db/db.drush.inc
	http/http.drush.inc
	platform/provision_drupal.drush.inc
	provision.inc
	provision.service.inc
parents ad58d6db 27244923
This diff is collapsed.
The Aegir system
================
This is the backend of the Aegir hosting system.
The front end and back end are designed to be run separately, and each
front end will also be able to drive multiple back ends.
The most up to date information regarding the project and its goal
can be found in the Aegir wiki page:
http://groups.drupal.org/aegir/overview
To install Aegir, you should follow the INSTALL.txt document in docs/.
The HINTS_<arch>.txt files can be useful if you have a specific
architecture, as out of the box, the examples for INSTALL.txt are for
Debian systems.
To upgrade Aegir, follow the UPGRADE.txt document in docs/.
The core of the documentation in docs/ should be sufficient to get you
started. If you have further questions or are having trouble with Aegir,
head for the documentation wiki:
http://groups.drupal.org/aegir-hosting-system/documentation
Other documentation for developpers is also available in docs/.
......@@ -4,3 +4,4 @@ projects[] = "drupal"
projects[hostmaster][type] = "profile"
projects[hostmaster][download][type] = "git"
projects[hostmaster][download][url] = "git://git.aegirproject.org/hostmaster.git"
projects[hostmaster][download][branch] = "dev-services"
<?php
function drush_db_pre_provision_backup($url = NULL) {
provision_service('db')->dump_site_database($url);
function drush_db_pre_provision_backup() {
provision_service('db')->generate_dump();
}
function drush_db_pre_provision_backup_rollback($url = NULL) {
provision_service('file')->unlink(drush_get_option('sites_path') . '/' . $url . '/database.sql')
function drush_db_pre_provision_backup_rollback() {
provision_service('file')->unlink(drush_get_option('sites_path') . '/' . drush_get_option('uri') . '/database.sql')
->succeed('Deleted mysql dump from sites directory')
->fail('Could not delete mysql dump from sites directory');
}
function drush_db_post_provision_backup($url = NULL) {
drush_db_pre_provision_backup_rollback($url);
function drush_db_post_provision_backup() {
drush_db_pre_provision_backup_rollback();
}
<?php
// $Id$
function drush_db_provision_clone_validate($url = null) {
provision_service('db')->connect($url);
function drush_db_provision_clone_validate() {
provision_service('db')->connect();
}
......@@ -8,21 +8,17 @@
* It uses the provision API to tie into the right places in the site creation work flow.
*/
include_once(dirname(__FILE__) . '/../provision.service.inc');
function db_provision_services() {
return array('db' => 'mysql');
}
function db_drush_exit() {
// determine how to close it too.
provision_service('db')->close();
}
function db_drush_help($section) {
switch ($section) {
case 'error:PROVISION_CREATE_DB_FAILED' :
......@@ -33,7 +29,6 @@ function db_drush_help($section) {
}
class provisionService_db extends provisionService {
function init() {
......@@ -82,7 +77,7 @@ class provisionService_db extends provisionService {
*
* TODO: abstract this properly.
*/
function suggest_db_name($url) {
function suggest_db_name() {
if ($sid = drush_get_option('site_id')) {
$suggest_base = drush_get_option('aegir_db_prefix', 'site_') . $sid;
}
......@@ -99,7 +94,7 @@ class provisionService_db extends provisionService {
// site name
//
// Provision only users will trigger this mostly.
$suggest_base = substr(str_replace(array(".", "-"), '' , ereg_replace("^www\.", "", $url)), 0, 14);
$suggest_base = substr(str_replace(array('.', '-'), '' , ereg_replace('^www\.', '', drush_get_option('uri'))), 0, 14);
}
$suggest[] = $suggest_base;
for ($i = 0; $i < 100; $i++) {
......@@ -121,8 +116,8 @@ class provisionService_db extends provisionService {
/**
* Generate a new mysql database and user account for the specified credentials
*/
function create_site_database($url) {
$creds = $this->generate_site_credentials($url);
function create_site_database() {
$creds = $this->generate_site_credentials();
extract($creds);
......@@ -137,7 +132,7 @@ class provisionService_db extends provisionService {
if (!$this->grant($db_name, $db_user, $db_passwd, $db_grant_host)) {
drush_log("Could not GRANT user access.", 'warning');
drush_set_error('PROVISION_CREATE_DB_FAILED', dt("Could not create database user @user", array('@user' => $db_user)));
}
$this->create_database($db_name);
......@@ -157,7 +152,7 @@ class provisionService_db extends provisionService {
/**
* Remove the database and user account for the supplied credentials
*/
function destroy_site_database($url) {
function destroy_site_database() {
$creds = $this->fetch_site_credentials();
extract($creds);
......@@ -180,8 +175,8 @@ class provisionService_db extends provisionService {
}
function import_site_database($url) {
$dump_file = drush_get_option('sites_path') .'/'. $url .'/database.sql';
function import_site_database() {
$dump_file = drush_get_option('sites_path') . '/' . drush_get_option('uri') . '/database.sql';
$creds = $this->fetch_site_credentials();
......@@ -200,14 +195,7 @@ class provisionService_db extends provisionService {
}
}
// todo - SORT THIS SHIT OUT!
function dump_site_database($url) {
return $this->generate_dump($url);
}
function generate_site_credentials($url) {
function generate_site_credentials() {
$creds = array();
// replace with service type
$db_type = drush_get_option('db_type');
......@@ -220,14 +208,14 @@ class provisionService_db extends provisionService {
$creds['db_type'] = drush_set_option('db_type', $db_type, 'site');
$creds['db_host'] = drush_set_option('db_host', drush_get_option('db_host'), 'site');
$creds['db_passwd'] = drush_set_option('db_passwd', provision_password(), 'site');
$creds['db_name'] = drush_set_option('db_name', $this->suggest_db_name($url), 'site');
$creds['db_name'] = drush_set_option('db_name', $this->suggest_db_name(), 'site');
$creds['db_user'] = drush_set_option('db_user', $creds['db_name'], 'site');
$creds['db_grant_host'] = $this->grant_host();
return $creds;
}
function fetch_site_credentials($url) {
function fetch_site_credentials() {
$creds = array();
$keys = array('db_type', 'db_user', 'db_name', 'db_host', 'db_passwd');
......@@ -267,7 +255,7 @@ class provisionService_db extends provisionService {
return FALSE;
}
function generate_dump($url) {
function generate_dump() {
return FALSE;
}
......@@ -275,11 +263,14 @@ class provisionService_db extends provisionService {
return 'localhost';
}
/**
* Write out server's drushrc alias file.
*/
function write_alias() {
return array(drush_get_option('provision-service-db') => array('provision-service-db', 'master_db'));
}
}
/**
* Indicates the place holders that should be replaced in _db_query_callback().
*/
......@@ -297,7 +288,7 @@ class provisionService_db_pdo extends provisionService_db {
function init() {
parent::init();
$this->dsn = sprintf("%s:dbname=%s;host=%s", $this->PDO_type, $this->creds['name'], $this->creds['host']);
$this->dsn = sprintf("%s:host=%s", $this->PDO_type, $this->creds['host']);
}
function connect() {
......
<?php
function drush_db_provision_delete_validate($url = null) {
function drush_db_provision_delete_validate() {
if (PROVISION_CONTEXT_SITE) {
provision_service('db')->connect();
}
......@@ -12,8 +11,8 @@ function drush_db_provision_delete_validate($url = null) {
*
* This will drop the database, revoke the privileges and flush the privileges.
*/
function drush_db_provision_delete($url = NULL) {
function drush_db_provision_delete() {
if (PROVISION_CONTEXT_SITE) {
provision_service('db')->destroy_site_database($url);
provision_service('db')->destroy_site_database();
}
}
......@@ -4,20 +4,20 @@ function drush_db_provision_deploy_validate() {
provision_service('db')->connect();
}
function drush_db_provision_deploy($url) {
provision_service('db')->create_site_database($url);
provision_service('db')->import_site_database($url);
function drush_db_provision_deploy() {
provision_service('db')->create_site_database();
provision_service('db')->import_site_database();
}
function drush_db_provision_deploy_rollback($url = NULL) {
provision_service('db')->destroy_site_database($url);
function drush_db_provision_deploy_rollback() {
provision_service('db')->destroy_site_database();
}
// Rollback doesn't apply here yet. Unless we trigger a deploy of the first dump
// made. Which could go on infinitely if something is really long.
function drush_db_post_provision_deploy($url) {
provision_service('file')->unlink(drush_get_option('sites_path') .'/'. $url .'/database.sql')
function drush_db_post_provision_deploy() {
provision_service('file')->unlink(drush_get_option('sites_path') . '/' . drush_get_option('uri') . '/database.sql')
->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
}
<?php
function drush_db_provision_install_validate($url) {
function drush_db_provision_install_validate() {
provision_service('db')->connect();
}
function drush_db_pre_provision_install($url) {
provision_service('db')->create_site_database($url);
function drush_db_pre_provision_install() {
provision_service('db')->create_site_database();
}
function drush_db_pre_provision_install_rollback($url) {
if (!_provision_drupal_site_installed($url)) {
provision_service('db')->destroy_site_database(
drush_get_option('db_name'), drush_get_option('db_user'),
drush_get_option('db_passwd')
);
function drush_db_pre_provision_install_rollback() {
if (!_provision_drupal_site_installed()) {
provision_service('db')->destroy_site_database();
}
......
......@@ -6,7 +6,7 @@ function drush_db_provision_migrate_validate() {
}
// Deletes the old database credentials
function drush_db_post_provision_migrate($url) {
function drush_db_post_provision_migrate() {
provision_service('db')->destroy_site_database(
drush_get_option('db_name'),
drush_get_option('db_user'),
......
......@@ -89,14 +89,12 @@ class provisionService_db_mysql extends provisionService_db_pdo {
return $matches[1];
}
//todo - SORT THIS SHIT OUT!
function generate_dump($url) {
# set the umask to 077 so that the dump itself is generated so it's non-readable by the webserver
function generate_dump() {
// Aet the umask to 077 so that the dump itself is generated so it's
// non-readable by the webserver.
umask(0077);
# mixed copy-paste of drush_shell_exec and provision_shell_exec
$cmd = sprintf("mysqldump --defaults-file=/dev/fd/3 -rsites/%s/database.sql %s", escapeshellcmd($url), escapeshellcmd(drush_get_option('db_name')));
// Mixed copy-paste of drush_shell_exec and provision_shell_exec.
$cmd = sprintf("mysqldump --defaults-file=/dev/fd/3 -rsites/%s/database.sql %s", escapeshellcmd(drush_get_option('uri')), escapeshellcmd(drush_get_option('db_name')));
$this->safe_shell_exec($cmd, drush_get_option('db_host'), urldecode(drush_get_option('db_user')), urldecode(drush_get_option('db_passwd')));
......@@ -104,12 +102,10 @@ class provisionService_db_mysql extends provisionService_db_pdo {
if (!$result && !drush_get_option('force', false)) {
drush_set_error('PROVISION_BACKUP_FAILED', dt("Could not generate database backup from mysqldump"));
}
# reset the umask to normal permissions
// Reset the umask to normal permissions.
umask(0022);
}
function safe_shell_exec($cmd, $db_host, $db_user, $db_passwd) {
# we go through all this trouble to hide the password from the commandline, it's the most secure way (apart from writing a temporary file, which would create conflicts in parallel runs)
$mycnf = sprintf('[client]
......
<?php
function drush_db_provision_restore_validate($url) {
provision_service('db')->connect($url);
function drush_db_provision_restore_validate() {
provision_service('db')->connect();
}
function drush_db_pre_provision_restore($url = NULL) {
provision_service('db')->create_site_database($url);
function drush_db_pre_provision_restore() {
provision_service('db')->create_site_database();
}
function drush_db_provision_restore($url) {
provision_service('db')->import_site_database($url);
function drush_db_provision_restore() {
provision_service('db')->import_site_database();
}
function drush_db_pre_provision_restore_rollback($url = NULL) {
provision_service('db')->destroy_site_db($url);
function drush_db_pre_provision_restore_rollback() {
provision_service('db')->destroy_site_database();
$keys = array('db_name', 'db_passwd', 'db_user', 'db_host');
......@@ -29,12 +29,12 @@ function drush_db_pre_provision_restore_rollback($url = NULL) {
// Rollback doesn't apply here yet. Unless we trigger a restore of the first dump
// made. Which could go on infinitely if something is really long.
function drush_db_post_provision_restore($url = NULL) {
provision_service('file')->unlink(drush_get_option('sites_path') . '/' . $url . '/database.sql')
function drush_db_post_provision_restore() {
provision_service('file')->unlink(drush_get_option('sites_path') . '/' . drush_get_option('uri') . '/database.sql')
->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
provision_service('db')->destroy_site_database($url);
provision_service('db')->destroy_site_database();
// TODO - test this .. it's probably horribly broken .. deleting the newly restored db instead of the old one.
......
......@@ -10,14 +10,7 @@ function drush_db_provision_verify_validate() {
* Can't be rolled back.
*/
function drush_db_provision_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
if (PROVISION_CONTEXT_SERVER) {
provision_service('db')->verify();
}
}
function drush_db_post_provision_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
drush_set_option('master_db', drush_get_option('master_db'), 'drupal');
}
}
......@@ -164,6 +164,12 @@ Shell commands as root::
a2enmod rewrite
ln -s /var/aegir/config/apache.conf /etc/apache2/conf.d/aegir.conf
That user needs to have sudo access. The wizard will explain you how to
do this, but you can already just add the relevant line to your sudoers
file.
/etc/sudoers configuration::
aegir ALL=NOPASSWD: /usr/sbin/apache2ctl
Database configuration
----------------------
......@@ -179,6 +185,18 @@ SQL commands::
CREATE TEMPORARY TABLES, LOCK TABLES ON aegir.* TO \
'aegir'@'localhost' IDENTIFIED BY 'XXXXXXXX';
The wizard will prompt you for another MySQL user. This is because Aegir
actually requires two database users: the above to drive the Drupal
frontend, and another, more privileged, to create databases and users
for new sites. You can already create that user before launching the
wizard using the following command.
SQL commands::
GRANT ALL PRIVILEGES ON *.* TO 'aegir_root'@'localhost' IDENTIFIED \
BY 'XXXXXXXX' WITH GRANT OPTION;
Again, change 'XXXXXXXX' with a real password.
DNS Configuration
-----------------
......
......@@ -37,8 +37,8 @@ Shell commands::
export AEGIR_VERSION=HEAD
export DRUPAL_DIR=/var/aegir/hostmaster-$AEGIR_VERSION
export OLD_DRUPAL_DIR=/var/aegir/drupal-6.14
export DRUSH_VERSION=All-versions-3.0-beta1
export OLD_DRUPAL_DIR=/var/aegir/hostmaster-0.4-alpha6
export DRUSH_VERSION=All-versions-3.0-rc4
export DRUSH_MAKE_VERSION=6.x-2.0-beta6
This document also assumes drush is installed properly and we use an
......
This diff is collapsed.
......@@ -138,7 +138,6 @@ class provisionService_file extends provisionService {
$func = ($recursive) ? array($this, '_chmod_recursive') : 'chmod';
if (!@call_user_func($func, $path, $perms)) {
$this->tokens['@reason'] = dt('chmod to @perm failed on @path', array('@perm' => sprintf('%o', $perms), '@path' => $path));
return false;
}
clearstatcache(); // this needs to be called, otherwise we get the old info
$this->last_status = substr(sprintf('%o', fileperms($path)), -4) == sprintf('%04o', $perms);
......@@ -149,7 +148,7 @@ class provisionService_file extends provisionService {
/**
* Change the owner of $path to the user in $owner.
*
* Sets @path, @owner, and @reason tokens for ->succeed and ->fail.
* Sets @path, @uid, and @reason tokens for ->succeed and ->fail.
*
* @param $path
* The path you want to perform this operation on.
......@@ -160,8 +159,12 @@ class provisionService_file extends provisionService {
*/
function chown($path, $owner, $recursive = FALSE) {
$this->_clear_state();
$this->tokens = array('@path' => $path, '@uid' => $owner);
$this->tokens = array('@path' => $path, '@gid' => $gid);
// We do not attempt to chown symlinks.
if (is_link($path)) {
return $this;
}
$func = ($recursive) ? array($this, '_chown_recursive') : 'chown';
if ($owner = provision_posix_username($owner)) {
......@@ -193,9 +196,13 @@ class provisionService_file extends provisionService {
*/
function chgrp($path, $gid, $recursive = FALSE) {
$this->_clear_state();
$this->tokens = array('@path' => $path, '@gid' => $gid);
// We do not attempt to chown symlinks.
if (is_link($path)) {
return $this;
}
$func = ($recursive) ? array($this, '_chgrp_recursive') : 'chgrp';
if ($group = provision_posix_groupname($gid)) {
if (provision_user_in_group(drush_get_option('script_user'), $gid)) {
......@@ -361,8 +368,8 @@ class provisionService_file extends provisionService {
if ($exists) {
$this->chown($path, drush_get_option('script_user'))
->succeed($name . ' ownership of path has been changed to @perm.')
->fail($name . ' ownership of path could not be changed to @perm.', 'DRUSH_PERM_ERROR');
->succeed($name . ' ownership of path has been changed to @uid.')
->fail($name . ' ownership of path could not be changed to @uid.', 'DRUSH_PERM_ERROR');
$this->chmod($path, $perms)
->succeed($name . ' permissions of path have been changed to @perm.')
......@@ -414,15 +421,17 @@ class provisionService_file extends provisionService {
$status = 1;
// do not follow symlinks as it could lead to a DOS attack
// consider someone creating a symlink from files/foo to ..: it would create an infinite loop
if (!is_link($path) && ($dh = @opendir($path))) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$status = $this->_call_recursive($func, $path . "/" . $file, $arg) && $status;
if (!is_link($path)) {
if ($dh = @opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$status = $this->_call_recursive($func, $path . "/" . $file, $arg) && $status;
}
}
closedir($dh);
}
closedir($dh);
$status = call_user_func($func, $path, $arg) && $status;
}
$status = call_user_func($func, $path, $arg) && $status;
return $status;
}
......
......@@ -13,12 +13,12 @@ class provisionService_http_apache extends provisionService_http {
$this->setProperty('restart_cmd', _provision_default_restart_cmd());
}
function create_site_config($url) {
function create_site_config() {
$config = new provisionConfig_apache_site(drush_get_merged_options());
return $config->write();
}
function delete_site_config($url) {
function delete_site_config() {
$config = new provisionConfig_apache_site(drush_get_merged_options());
return $config->unlink();
}
......@@ -28,7 +28,7 @@ class provisionService_http_apache extends provisionService_http {
return $config->write();
}
function delete_platform_config($url) {
function delete_platform_config() {
$config = new provisionConfig_apache_platform(drush_get_merged_options());
return $config->unlink();
}
......@@ -40,35 +40,38 @@ class provisionService_http_apache extends provisionService_http {
}
function delete_server_config($url) {
function delete_server_config() {
$config = new provisionConfig_apache_server(drush_get_merged_options());
return $config->unlink();
}
function verify($url) {
function verify() {
if (PROVISION_CONTEXT_PLATFORM) {
$this->create_platform_config();
}
elseif (PROVISION_CONTEXT_SERVER) {
provision_service('file')->create_dir(drush_get_option('vhost_path'), dt("Virtual host configuration"), 0700);
provision_service('file')->create_dir(drush_get_option('platform_conf_path'), dt("Platforms configuration"), 0700);
provision_service('file')->create_dir(drush_get_option('config_path') . '/apache.d' , dt("Apache configuration"), 0700);
if (drush_get_option('platform', null)) {
$this->create_platform_config();
}
$this->create_server_config();
}
else {
$this->create_site_config($url);
elseif (PROVISION_CONTEXT_SITE) {
$this->create_site_config();
}
$this->parse_configs();
}
function parse_configs($cause_error = FALSE) {
//This is required to be configurable, due to the fact that different hosts might need to do this differently.
//TODO : test for this instead of relying on a configuration setting?
$return = drush_shell_exec(escapeshellcmd(drush_get_option('restart_cmd')));
// This is required to be configurable, due to the fact that different
// hosts might need to do this differently.
if (drush_is_local_host(drush_get_option('web_host'))) {
$return = drush_shell_exec(escapeshellcmd(drush_get_option('restart_cmd')));
}
else {
$return = drush_shell_exec('ssh ' . drush_get_option('ssh-options', '-o PasswordAuthentication=no') . ' %s %s', drush_get_option('script_user') . '@' . drush_get_option('web_host'), escapeshellcmd(drush_get_option('restart_cmd')));
}
if (!$return) {
$msg = join("\n", drush_shell_exec_output());
if ($cause_error) {
......@@ -112,7 +115,7 @@ class provisionConfig_apache_platform extends provisionConfig_apache {
public $description = 'apache platform configuration file';
function filename() {
return $this->data['platform_conf_path'] . '/platform_' . $this->data['platform'] . '.conf';
return $this->data['platform_conf_path'] . '/platform_' . $this->data['platform-name'] . '.conf';
}
function process() {
......@@ -126,14 +129,14 @@ class provisionConfig_apache_site extends provisionConfig_apache {
public $description = 'apache site configuration file';
function filename() {
if (!$this->data['site_port'] || $this->data['site_port'] < 1 || $this->data['site_port'] > 66535) {
$this->data['site_port'] = 80;
}
return $this->data['vhost_path'] . '/' . $this->data['site_url'] . '_' . $this->data['site_port'];
}
function process() {
if (!$this->data['site_port'] || $this->data['site_port'] < 1 || $this->data['site_port'] > 66535) {
$this->data['site_port'] = 80;
}
if ($this->data['aliases'] && !is_array($this->data['aliases'])) {
$this->data['aliases'] = explode(",", $this->data['aliases']);
}
......
<?php
function drush_http_provision_delete($url = NULL) {
function drush_http_provision_delete() {
if (PROVISION_CONTEXT_SITE) {
provision_service('http')->delete_site_config($url);
provision_service('http')->delete_site_config();
}
if (PROVISION_CONTEXT_PLATFORM) {
$sites = provision_drupal_find_sites();
......
<?php
function drush_http_post_provision_deploy($url = NULL) {
provision_service('http')->create_site_config($url);
function drush_http_post_provision_deploy() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
}
/**
* Delete the config file created.
*/
function drush_http_post_provision_deploy_rollback($url = NULL) {
provision_service('http')->create_site_config($url);
function drush_http_post_provision_deploy_rollback() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
}
......@@ -3,11 +3,11 @@
/**
* Implementation of hook_provision_disable
*/
function drush_http_provision_disable($url = NULL) {
function drush_http_provision_disable() {
drush_set_option('redirect_url', drush_get_option('web_disable_url'));
// TODO - this is majorly wrong i think.
provision_service('http')->create_site_config($url);
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
}
......@@ -3,8 +3,8 @@
/**
* Implementation of hook_provision_enable
*/
function drush_http_provision_enable($url = NULL) {
provision_service('http')->create_site_config($url);
function drush_http_provision_enable() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
}
......@@ -32,21 +32,21 @@ class provisionService_http extends provisionService {
/**
* Generate a site specific configuration file
*/
function create_site_config($url) {
function create_site_config() {
return TRUE;
}
/**
* Remove an existing site configuration file.
*/
function delete_site_config($url) {
function delete_site_config() {
return TRUE;
}
/**
* Add a new platform specific configuration file.
*/
function create_platform_config($url) {
function create_platform_config() {
return TRUE;
}
......@@ -62,7 +62,6 @@ class provisionService_http extends provisionService {
*/
function create_server_config() {
return TRUE;
}
/**
......@@ -71,4 +70,15 @@ class provisionService_http extends provisionService {
function delete_server_config() {
return TRUE;
}
/**
* Write out server's drushrc alias file.
*/