migrate.hostmaster.inc 5.47 KB
Newer Older
1 2 3 4 5 6
<?php

/**
 * @file manual site migrate system
 */
function drush_provision_hostmaster_migrate_validate($site, $platform) {
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  // XXX: this doesn't actually document the pre alpha9 upgrade path
  drush_print('
This command will operate the following changes in your system:

1. verify the server and the hostmaster site (provision-verify)
2. verify the new platform (which will download it if missing)
3. stop the Aegir frontend (hostmaster-pause)
4. remove the cronjob (crontab -r)
5. attempt a migration to the new platform (provision-migrate)
6. start the Aegir frontend again (hostmaster-resume)

We are making the following assumptions:
 * you have read UPGRADE.txt
 * you are executing this script as your "aegir" user
');

23 24
  if (!drush_confirm("Do you really want to proceed with the upgrade?")) {
    return drush_set_error('PROVISION_CANCEL_MIGRATE', 'Upgrade canceled by user');
25 26
  }

27
  $data = drush_get_merged_options();
28

29
  $alias_file = drush_server_home() . '/.drush/server_master.alias.drushrc.php';
30

31 32 33 34 35 36 37
  if (!file_exists($platform)) {
    $dir = realpath(dirname($platform));
    if (file_exists($dir)) {
      $platform = $dir . '/' . basename($platform);
      drush_log("changed relative platform path to absolute");
    }
  }
38

39 40 41 42
  // If the alias file exists, it means we are migrating from a post alpha9 release.
  if (file_exists($alias_file)) {
    provision_backend_invoke('@server_master', 'provision-verify');
    provision_backend_invoke('@hostmaster', 'provision-verify');
43

44
    drush_set_option('site_name', '@hostmaster');
45
    drush_set_option('old_platform', d('@hostmaster')->platform->name);
46

47 48 49 50 51 52
    $new_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($platform, '/')));
    drush_backend_invoke_args("provision-save", array($new_platform), array(
      'context_type' => 'platform',
      'server' => '@server_master',
      'web_server' => '@server_master',
      'root' => $platform,
53
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
54 55 56 57 58 59 60
    ));
    provision_backend_invoke($new_platform, 'provision-verify');
    drush_set_option('new_platform', $new_platform);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }
61
  }
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  else {

    // add a server record :
    $server = '@server_master';
    drush_backend_invoke_args("provision-save", array($server), array(
      'context_type' => 'server',
      'aegir_root' => dirname(rtrim($data['config_path'], '/')),
      'remote_host' => php_uname('n'),
      'script_user' => $data['script_user'],
     // apache or nginx or..
      'http_service_type' => drush_get_option('http_service_type', 'apache', 'options'),
      'web_group' => $data['web_group'],
      'master_url' => $data['master_url'],
      'restart_cmd' => $data['restart_cmd'],
     // mysql
      'db_service_type' => 'mysql',
      'master_db' => $data['master_db'],
    ));
80

81 82 83 84 85 86
    provision_backend_invoke($server, 'provision-verify');
    drush_set_option('server_name', $server);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
   
    $old_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($data['publish_path'], '/')));
    drush_backend_invoke_args("provision-save", array($old_platform), array(
      'context_type' => 'platform',
      'server' => $server,
      'web_server' => $server,
      'root' => $data['publish_path'],
    ));
    provision_backend_invoke($old_platform, 'provision-verify');
    drush_set_option('old_platform', $old_platform);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }

    $new_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($platform, '/')));
    drush_backend_invoke_args("provision-save", array($new_platform), array(
      'context_type' => 'platform',
      'server' => $server,
      'web_server' => $server,
      'root' => $platform,
109
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    ));
    provision_backend_invoke($new_platform, 'provision-verify');
    drush_set_option('new_platform', $new_platform);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }


    $site_name = '@hostmaster';
    drush_backend_invoke_args("provision-save", array($site_name), array(
      'context_type' => 'site',
      'platform' => $old_platform,
      'db_server' => $server,
      'uri' => $site,
      'profile' => 'hostmaster',
    ));
    provision_backend_invoke($site_name, 'provision-verify');
    drush_set_option('site_name', $site_name);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }
  }
134 135
}

136

137
function drush_provision_pre_hostmaster_migrate($site, $platform) {
138 139 140 141
  // wipe out cron entry
  exec('crontab -r');

  // we can't rely on the park command to exist in pre-0.4 alpha 2 releases
142
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-pause');
143 144
}

145
function drush_provision_hostmaster_migrate($site, $platform) {
Adrian Rossouw's avatar
Adrian Rossouw committed
146
  provision_backend_invoke(drush_get_option('site_name'), 'provision-migrate', array(drush_get_option('new_platform')));
147 148 149
}

function drush_provision_post_hostmaster_migrate($site, $platform) {
150 151
  // we pass the context names we generated to the task so we can enforce that the names
  // stay the same.
Adrian Rossouw's avatar
Adrian Rossouw committed
152
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-resume', array(), array( 
153 154
    'old_platform_name' => drush_get_option('old_platform'),
    'new_platform_name' => drush_get_option('new_platform'),
Adrian Rossouw's avatar
Adrian Rossouw committed
155
  ));
156 157
}