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

frankcarey - October 7, 2009 - 00:28
Project:Provision
Version:6.x-0.4-alpha1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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!

#1

anarcat - October 7, 2009 - 20:09
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

mig5 - November 10, 2009 - 03:24

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

mig5 - November 10, 2009 - 06:20

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

mig5 - November 10, 2009 - 06:33

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

mig5 - November 10, 2009 - 08:52
 
 

Drupal is a registered trademark of Dries Buytaert.