Download & Extend

We shouldn't provision install more than once on the same site

Project:Provision
Version:6.x-0.4-alpha1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I am trying to debug another issue and realized that every time I ran
drush provision install mysite.com

it creates a new database, and new user. talked with mig5 on #aegir and he said that he doubts this should be allowed, but wasn't 100%.

I did this 30 times, trying to pipe output to sed.... and ended up with 30 databases!

Comments

#1

Priority:critical» normal

That is a bug: this should fail with a message that the site exists. I don't see this as a critical issue however.

#2

I think I can fix this by using _provision_drupal_site_installed($url) in drush_provision_drupal_provision_install_validate($url) . I'll update if it works

#3

Except a bigger problem emerges: when _validate fails, and _rollback runs, the sites/www.whatever.com is deleted :) which is not what you want when it is detected that the site already exists! This means that the _rollback implementation will need to be changed.. maybe. hum.

#4

I have it working if I add a check to see if the site is installed in the _rollback implementations, for instance in platform/install.provision.inc (leaving the previous conditional but commented out so you can see)

<?php
/**
* If the install went south, and the site is not PROVISION_SITE_INSTALLED, clean up behind ourselves
*/
function drush_provision_drupal_provision_install_rollback($url) {
 
//if (!drush_cmp_error('PROVISION_SITE_INSTALLED')) {
 
if (!_provision_drupal_site_installed($url)) {
    if (
$url) {
     
_provision_recursive_delete("sites/$url");
    } else {
     
drush_set_error('PROVISION_FRAMEWORK_ERROR', dt('no url defined in %function', array('%function' => __FUNCTION__)));
    }
  }
}
?>

and again in db_server/install.provision.inc (so that rollback when the existing site is found, doesn't drop the db / grants)

<?php
function drush_provision_mysql_pre_provision_install_rollback($url = NULL) {
  if (!
_provision_drupal_site_installed($url)) {
   
_provision_mysql_destroy_site_db(drush_get_option('db_name'), drush_get_option('db_user'), drush_get_option('db_passwd'));
  }
}
?>

That way it will only run the rollback if the site was not yet finished installing (i.e it depends on drush_get_option('installed');), and all this occurs if it triggers the problem in the hook_validate:

<?php
/**
* Check that we are trying to install a new site , and a new site only
*/
function drush_provision_drupal_provision_install_validate($url) {
  if (!
$url) {
    return
drush_set_error("PROVISION_URL_REQUIRED", dt("You need to specify a valid url to install a site"));
  }
  if (
_provision_drupal_site_installed($url)) {
    return
drush_set_error('PROVISION_SITE_INSTALLED');
  }
}
?>

However I don't know if this is the right way (can we rely on the idea that in any *other* case where an install might fail (whether or not a site of the same name exists), the context will report 'installed' by that point, so that proper rollback WILL occur ). For this reason I haven't committed/submitted a patch for review yet, I'm unsure if this is the right way to go about it.

#5

#6

Status:needs review» fixed

Push to head, thanks mig5!

#7

Status:fixed» needs work

So I reverted that commit in the end, it introduces a regression where the site_id is not passed to the backend properly, which breaks backups, amongst other things, and create a silly drushrc.php:

<?php
$options
['db_type'] = 'mysqli';
$options['db_host'] = 'localhost';
$options['db_passwd'] = 'AdeuUduBzx';
$options['db_name'] = 'bara01examplecom';
$options['db_user'] = 'bara01examplecom';
$options['installed'] = true;
$options['aliases'] = array (
);
$options['site_url'] = 'bara01.example.com';
$options['site_id'] = NULL;
$options['client_email'] = NULL;

$_SERVER['db_type'] = 'mysqli';
$_SERVER['db_host'] = 'localhost';
$_SERVER['db_user'] = 'bara01examplecom';
$_SERVER['db_passwd'] = 'AdeuUduBzx';
$_SERVER['db_name'] = 'bara01examplecom';
?>

Backups break like this:

Running:  /var/aegir/drush/drush.php  --db_id='2' --profile='default'  [command]
--site_port='80' --platform='71'
--publish_path='/var/aegir/plateformes/drupal-6.14-1.0-prod'
--site_id='291' --language='en' --ssl='0' --ssl_redirect='0'
--drush_path='/var/aegir/drush/drush.php' --web_id='3'
--web_host='aegir.example.com' --web_ip='209.44.112.153'
--script_user='aegir'
--root='/var/aegir/plateformes/drupal-6.14-1.0-prod'  'provision'
'backup' 'bara01.example.com' --backend [0.237 sec]
Drush bootstrap phase : _drush_bootstrap_drush() [0.442 sec]         [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.443 sec]   [bootstrap]
Loading drushrc                                                      [bootstrap]
"/var/aegir/plateformes/drupal-6.14-1.0-prod/drushrc.php" into
"drupal" scope. [0.443 sec]
Initialized Drupal 6.14 root directory at                               [notice]
/var/aegir/plateformes/drupal-6.14-1.0-prod [0.443 sec]
Found command: provision backup [0.444 sec]                          [bootstrap]
Initializing drush commandfile: provision_apache [0.444 sec]         [bootstrap]
Undefined index:  base_url [0.445 sec]                                  [notice]
Initializing drush commandfile: provision_drupal [0.445 sec]         [bootstrap]
Initializing drush commandfile: provision_mysql [0.446 sec]          [bootstrap]
Undefined index:  db_url [0.446 sec]                                    [notice]
Including /var/aegir/.drush/provision/platform/backup.provision.inc  [bootstrap]
[0.446 sec]
Including /var/aegir/.drush/provision/db_server/backup.provision.inc [bootstrap]
[0.447 sec]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.447 sec]   [bootstrap]
Initialized Drupal site bara01.example.com at sites/bara01.example.com      [notice]
[0.448 sec]
Loading drushrc                                                      [bootstrap]
"/var/aegir/plateformes/drupal-6.14-1.0-prod/sites/bara01.example.com/drushrc.php"
into "site" scope. [0.448 sec]
Generating mysql dump for bara01.example.com. [0.448 sec]                 [backup]
mysqldump --defaults-file=/dev/fd/3                                     [notice]
-rsites/bara01.example.com/database.sql bara01examplecom [0.449 sec]
Could not generate database backup from mysqldump [0.449 sec]        [error]
An error occurred at function :                                      [error]
drush_provision_mysql_pre_provision_backup [0.45 sec]
Could not delete mysql dump from sites directory [0.45 sec]          [warning]
Changes for drush_provision_mysql_pre_provision_backup module have    [rollback]
been rolled back. [0.45 sec]
Command dispatch complete [0.451 sec]                                   [notice]
An error occurred at function : drush_hosting_hosting_task [0.454    [error]
sec]
Changes for drush_hosting_hosting_task module have been rolled back.  [rollback]
[0.455 sec]
Command dispatch complete [0.455 sec]                                   [notice]
Timer 'page' is  0.395 sec. [0.456 sec]                                  [timer]

#8

Title:Drush can run provision install more than once on the same site, should this be?» We should provision install more than once on the same site

The only explanation I could think of here is this:

<?php
-  if (drush_get_option('installed')) {
-   
drush_set_error('PROVISION_SITE_INSTALLED');
+  if (
_provision_drupal_site_installed($url)) {
?>

... ie. that _provision_drupal_site_installed() would do something special.

Note that I'm running provision HEAD + Hostmaster 0.4-alpha3.

#9

Title:We should provision install more than once on the same site» We shouldn't provision install more than once on the same site
Status:needs work» fixed

anarcat fixed this stupid regression of mine, tested and works as expected.

#10

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here