Commit de1d8043 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

#321942 (primarily) - working config file generation and synch command. Also...

#321942 (primarily) - working config file generation and synch command. Also cleaned up variables passed to the system so the site_ prefix is no longer used.
parent 8ba84b5a
......@@ -43,7 +43,7 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host)
function _provision_mysql_destroy_site_db($db_name, $db_user, $db_passwd, $db_host) {
provision_set_active_db(_provision_master_db_url());
if ( _provision_mysql_database_exists($data['site_db_name']) ) {
if ( _provision_mysql_database_exists($data['db_name']) ) {
provision_log("notice", t("Dropping database @dbname", array('@dbname' => $db_name)));
_provision_mysql_drop_database($db_name);
}
......
......@@ -48,96 +48,47 @@ EOF;
return $help;
}
/**
* Implementation of provision_service()
*/
function provision_mysql_provision_service() {
return array("db_server" => t("Mysql database server"));
}
/**
* Implementation of provision_configure
*/
function provision_mysql_provision_configure($node = NULL) {
if (!is_object($node) && ($nid = variable_get('hosting_own_db_server', 0))) {
$node = node_load($nid);
}
$form['db_type'] = array('#type' => 'hidden', '#value' => ($node->db_type) ? $node->db_type : PROVISION_DB_TYPE);
$form['db_host'] = array(
'#type' => 'textfield',
'#title' => t('Database server hostname'),
'#description' => t('The address of the database server to connect to.'),
'#size' => 30,
'#default_value' => ($node->db_host) ? $node->db_host : PROVISION_DB_HOST,
'#maxlength' => 64,
'#weight' => 0,
);
$form['db_user'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => t('Username'),
'#description' => t('The user that will be used to create users and databases for new sites.'),
'#size' => 40,
'#default_value' => ($node->db_user) ? $node->db_user : PROVISION_DB_USER,
'#maxlength' => 255,
'#weight' => 5,
);
if ($node->db_passwd) {
$passwd_description = t('<strong>You have already set a password for this database server.</strong><br />');
}
$form['db_passwd'] = array(
'#type' => 'password_confirm',
'#required' => (PROVISION_DB_PASSWD) ? FALSE : TRUE,
'#description' => $passwd_description . t('The user account that will be used to create new mysql users and databases for new sites'),
'#size' => 30,
'#weight' => 10
);
return $form;
}
/**
* @} end "ingroup provisionui"
*/
function provision_mysql_provision_pre_install($url, &$data) {
$data['site_db_type'] = ($data['site_db_type']) ? $data['site_db_type'] : PROVISION_DB_TYPE;
$data['site_db_host'] = ($data['site_db_host']) ? $data['site_db_host'] : PROVISION_DB_HOST;
$data['db_type'] = ($data['db_type']) ? $data['db_type'] : PROVISION_DB_TYPE;
$data['db_host'] = ($data['db_host']) ? $data['db_host'] : PROVISION_DB_HOST;
# generate a random password for use
$data['site_db_passwd'] = user_password();
$data['site_db_name'] = _provision_mysql_suggest_db_name($url, $data);
$data['site_db_user'] = $data['site_db_name'];
$data['db_passwd'] = user_password();
$data['db_name'] = _provision_mysql_suggest_db_name($url, $data);
$data['db_user'] = $data['db_name'];
return _provision_mysql_new_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
return _provision_mysql_new_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
}
function provision_mysql_provision_pre_install_rollback($url, &$data) {
_provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
unset($data['site_db_host']);
unset($data['site_db_type']);
unset($data['site_db_passwd']);
unset($data['site_db_user']);
unset($data['site_db_name']);
_provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
unset($data['db_host']);
unset($data['db_type']);
unset($data['db_passwd']);
unset($data['db_user']);
unset($data['db_name']);
}
function provision_mysql_provision_pre_restore($url, &$data) {
// store a backup of the credentials of the site.
$data['old_site_db_name'] = $data['site_db_name'];
$data['old_site_db_passwd'] = $data['site_db_passwd'];
$data['old_site_db_user'] = $data['site_db_user'];
$data['old_site_db_host'] = $data['site_db_host'];
$data['old_db_name'] = $data['db_name'];
$data['old_db_passwd'] = $data['db_passwd'];
$data['old_db_user'] = $data['db_user'];
$data['old_db_host'] = $data['db_host'];
# generate a random password for use
$data['site_db_passwd'] = user_password();
$data['site_db_name'] = _provision_mysql_suggest_db_name($url, $data);
$data['site_db_user'] = $data['site_db_name'];
$data['db_passwd'] = user_password();
$data['db_name'] = _provision_mysql_suggest_db_name($url, $data);
$data['db_user'] = $data['db_name'];
$success = _provision_mysql_new_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
$success = _provision_mysql_new_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
if ($success) {
_provision_mysql_import_dump(PROVISION_SITES_PATH .'/'. $url .'.restore/database.sql', $data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
_provision_mysql_import_dump(PROVISION_SITES_PATH .'/'. $url .'.restore/database.sql', $data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
}
else {
provision_set_error(PROVISION_DB_ERROR);
......@@ -146,7 +97,7 @@ function provision_mysql_provision_pre_restore($url, &$data) {
}
function provision_mysql_provision_pre_restore_rollback($url, &$data) {
_provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
_provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
//Restore the original database credentials of the site.
foreach ($keys as $key) {
......@@ -160,7 +111,7 @@ function provision_mysql_provision_pre_restore_rollback($url, &$data) {
* This will drop the database, revoke the privileges and flush the privileges.
*/
function provision_mysql_provision_delete($url, &$data) {
return _provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
return _provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
}
// Rollback doesn't apply here yet. Unless we trigger a restore of the first dump
......@@ -169,13 +120,13 @@ function provision_mysql_provision_post_restore($url, &$data) {
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE,
t("Removed dump file @path after restoring from it"),
t("Could not remove dump file @path"), PROVISION_PERM_ERROR);
return _provision_mysql_destroy_site_db($data['old_site_db_name'], $data['old_site_db_user'], $data['old_site_db_passwd'], $data['old_site_db_host']);
return _provision_mysql_destroy_site_db($data['old_db_name'], $data['old_db_user'], $data['old_db_passwd'], $data['old_db_host']);
}
function provision_mysql_provision_backup($url, &$data) {
provision_log("backup", "Generating mysql dump for $url.");
provision_shell_exec("mysqldump -u%s -p%s %s > sites/%s/database.sql", $data['site_db_user'], $data['site_db_passwd'], $data['site_db_name'], $url);
provision_shell_exec("mysqldump -u%s -p%s %s > sites/%s/database.sql", $data['db_user'], $data['db_passwd'], $data['db_name'], $url);
provision_shell_exec("cd sites/%; tar -rf %s database.sql; rm database.sql", $url, $data['backup_file']);
}
......@@ -194,4 +145,4 @@ function provision_mysql_provision_verify() {
provision_log("message", t('Mysql can create new databases.'));
}
provision_set_active_db();
}
\ No newline at end of file
}
......@@ -423,8 +423,11 @@ function _provision_drupal_get_cvs_versions($files) {
function provision_drupal_provision_import($url, &$data) {
$sites = provision_drupal_find_sites();
foreach ($sites as $site => $file) {
if ($site == 'default') {
continue;
}
$info = _provision_drupal_import_site($site);
if ($info['site_installed']) {
if ($info['installed']) {
provision_log("notice", "Returning information for $site");
$data['sites'][$site] = $info;
}
......@@ -441,11 +444,11 @@ function _provision_drupal_import_site($url) {
include("sites/$url/settings.php");
if ($parts = @parse_url($db_url)) {
$data['site_db_type'] = $parts['scheme'];
$data['site_db_user'] = $parts['user'];
$data['site_db_host'] = $parts['host'];
$data['site_db_passwd'] = $parts['pass'];
$data['site_db_name'] = substr($parts['path'], 1);
$data['db_type'] = $parts['scheme'];
$data['db_user'] = $parts['user'];
$data['db_host'] = $parts['host'];
$data['db_passwd'] = $parts['pass'];
$data['db_name'] = substr($parts['path'], 1);
/**
* We need to be running AS the site to be able to see what profile it is installed with.
......@@ -454,14 +457,14 @@ function _provision_drupal_import_site($url) {
*/
provision_set_active_db($db_url);
$install_profile = db_result(db_query("SELECT value FROM {variable} WHERE name='install_profile'"));
$data['site_profile'] = ($install_profile) ? unserialize($install_profile) : 'default';
$data['profile'] = ($install_profile) ? unserialize($install_profile) : 'default';
$has_locale = db_result(db_query("SELECT status FROM {system} WHERE type='module' AND name='locale'"));
if ($has_locale) {
$locale = db_result(db_query("SELECT locale FROM {locales_meta} WHERE isdefault=1 AND enabled=1"));
}
$data['site_language'] = ($locale) ? ($locale) : 'en';
$data['language'] = ($locale) ? ($locale) : 'en';
provision_close_active_db();
$data['site_installed'] = TRUE;
$data['installed'] = TRUE;
}
provision_save_site_data($url, $data);
......
$db_url = '<?php print "$site_db_type://$site_db_user:$site_db_passwd@$site_db_host/$site_db_name"; ?>';
$profile = "<?php print $site_profile ?>";
<?php if ($site_locale != 'en') : ?>
$locale = '<?php print $site_locale; ?>';
<?php endif; ?>
$db_url = '<?php print "$db_type://$db_user:$db_passwd@$db_host/$db_name"; ?>';
$profile = "<?php print $profile ?>";
/**
* PHP settings:
*
......
......@@ -280,21 +280,17 @@ function provision_get_log() {
function provision_get_site_data($url) {
global $args;
//TODO: Accept serialized string via unix pipe.
foreach ($args['options'] as $key => $value) {
if (preg_match("/^site_/", $key)) {
$site_data[$key] = $value;
}
}
$site_data = $args['options'];
$site_data['site_url'] = $url;
$site_data['task_type'] = $args['commands'][1];
$site_data['task_id'] = drush_get_option('task_id', NULL);
$site_data['publish_path'] = PROVISION_DOCROOT_PATH;
$site_data['site_profile'] = ($site_data['site_profile']) ? $site_data['site_profile'] : variable_get('provision_default_profile', 'default');
$site_data['profile'] = ($site_data['profile']) ? $site_data['profile'] : variable_get('provision_default_profile', 'default');
$site_data['site_ip'] = variable_get('provision_apache_server_ip', '127.0.0.1');
$site_data['site_port'] = variable_get('provision_apache_server_ip', 80);
//Default to english language
$site_data['site_language'] = $site_data['site_language'] ? $site_data['site_language'] : 'en';
$site_data['language'] = $site_data['language'] ? $site_data['language'] : 'en';
if ($old_data = provision_load_site_data($url)) {
//Merge previously saved data with the new data. This way, old parameters overwrite new ones.
......@@ -358,12 +354,9 @@ function provision_save_site_data($url, $data) {
fwrite($fp, $line);
}
foreach ($data as $key => $value) {
if (preg_match('/^site_/', $key)) {
if ($data[$key] != $old_data[$key]) {
$line = "\n\$data['$key'] = ". var_export($value, TRUE) .';';
fwrite($fp, $line);
}
if ($data[$key] != $old_data[$key]) {
$line = "\n\$data['$key'] = ". var_export($value, TRUE) .';';
fwrite($fp, $line);
}
}
fclose($fp);
......@@ -391,12 +384,12 @@ function provision_save_site_data($url, $data) {
function provision_value_list() {
/** TODO: Complete the value list to allow the front end to more easily edit the settings. */
$values['site_url'] = t('The domain name used to access the site. This is defaulted to the value used on the command line.');
$values['site_db_type'] = t('The type of database server used');
$values['site_db_username'] = t('Username to access database for site');
$values['site_db_password'] = t('Password to access database for site');
$values['site_db_name'] = t('Database name for the site');
$values['site_profile'] = t('Install profile of site');
$values['site_task_type'] = t('What type of task has been used. Only used in conjuction with hosting front end');
$values['db_type'] = t('The type of database server used');
$values['db_username'] = t('Username to access database for site');
$values['db_password'] = t('Password to access database for site');
$values['db_name'] = t('Database name for the site');
$values['profile'] = t('Install profile of site');
$values['task_type'] = t('What type of task has been used. Only used in conjuction with hosting front end');
return $values;
}
......
This diff is collapsed.
/**
* This configuration file manages the settings for the provisionining back end of the Aegir hosting system.
*
* This file was automatically created for you by the provision setup functionality, to test the settings in
* this file, please run the provision verify command.
*
*/
/**
* Directory to store site backups.
*
* If you have multiple provision managed platforms on this system, it is highly
* recommended to use the same path for each platform you have.
*/
define('PROVISION_BACKUP_PATH', '<?php print $backup_path ?>');
/**
* Directory to store configuration files
*
* All system related configuration files will be stored here.
*
* If you have multiple provision managed platforms on this server, it is highly
* recommended to use the same path for each platform you have.
*/
define('PROVISION_CONFIG_PATH', '<?php print $config_path ?>');
/**
* The login name for the shell user who will be running the provision scripts
*
* This needs to be a user account that is not root or the web server user.
*/
define('PROVISION_SCRIPT_USER', '<?php print $script_user ?>');
/**
* The group that the web server is running as
*/
define('PROVISION_WEB_GROUP', '<?php print $web_group ?>');
/**
* Database credentials for a database account capable of creating databases and users
*/
define('PROVISION_MASTER_DB', '<?php print $master_db ?>');
/**
* Command to restart apache when an action has been completed
*/
define('PROVISION_RESTART_CMD', '<?php print $restart_cmd ?>');
/**
* The address of the Hostmaster installation
* This url will be used to redirect sites that haven't been found or have been disabled.
*/
define('PROVISION_MASTER_URL', '<?php print $master_url ?>');
......@@ -11,10 +11,6 @@
* to ensure that the sites are getting loaded up correctly.
*/
function provision_apache_provision_service() {
return array( "web_server" => t("Web Server"));
}
/**
* Implementation of hook_help().
*/
......@@ -99,82 +95,7 @@ EOF;
}
/**
* Hook into central configuration form for provisioning framework.
*/
function provision_apache_provision_configure($node = NULL) {
// We need to define form elements for the node's title and body.
$form['restart_cmd'] = array(
'#type' => 'textfield',
'#title' => t('Restart command'),
'#required' => TRUE,
'#description' => t('The command to run to restart the for new changes to take effect. This is required for the new site to become live'),
'#default_value' => ($node->restart_cmd) ? $node->restart_cmd : PROVISION_RESTART_CMD,
'#size' => 40,
'#maxlength' => 255,
'#weight' => -20,
);
$form['script_user'] = array(
'#type' => 'textfield',
'#title' => t('System account'),
'#required' => TRUE,
'#description' => t('The system account that the hosted files will belong to, for security reasons.<br />This should be a different to the account the web server is running as.'),
'#default_value' => ($node->script_user) ? $node->script_user : PROVISION_SCRIPT_USER,
'#size' => 20,
'#maxlength' => 255,
'#weight' => -15,
);
$form['web_group'] = array(
'#type' => 'textfield',
'#title' => t('Web server group'),
'#required' => TRUE,
'#description' => t('The group that the hosted files will belong to.<br />This should be the group the web server is running as.'),
'#default_value' => ($node->web_group) ? $node->web_group : PROVISION_WEB_GROUP,
'#size' => 20,
'#maxlength' => 75,
'#validate' => array('provision_apache_validate_web_group' => array()),
'#weight' => -10,
);
$form['config_path'] = array(
'#type' => 'textfield',
'#title' => t('Configuration path'),
'#required' => TRUE,
'#size' => 40,
'#default_value' => ($node->config_path) ? $node->config_path : PROVISION_CONFIG_PATH,
'#description' => t("The path on the server where configuration files will be stored.<br />
It is essential that this directory should not be accessible via a web browser."),
'#maxlength' => 255,
'#weight' => -10,
);
$form['backup_path'] = array(
'#type' => 'textfield',
'#title' => t('Backup path'),
'#required' => TRUE,
'#size' => 40,
'#default_value' => ($node->backup_path) ? $node->backup_path : PROVISION_BACKUP_PATH,
'#description' => t("The path on the server where backups will be stored.<br />
It is essential that this directory should not be accessible via a web browser."),
'#maxlength' => 255,
'#weight' => -10,
);
return $form;
}
function provision_apache_validate_web_group($element) {
$user = $element['#post']['script_user'];
$group = $element['#post']['web_group'];
if ($user && $group) {
if (!provision_user_in_group($user, $group)) {
form_set_error('web_group', t("The %user user is not in the %group group. For information on how to fix this, please check the !link.",
array('%user' => $user, '%group' => $group, '!link' => l(t("provisioning requirements"), "admin/help/provision/requirements") )));
}
}
}
/**
* Implementation of hook_provision_templates
......
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