migrate.hostmaster.inc 5.87 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
  // 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)
13 14 15
3. stop the queue (hosting-pause)
4. attempt a migration to the new platform (provision-migrate)
5. start the queue (hosting-resume)
16 17 18 19 20 21

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

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

26
  $data = drush_get_merged_options();
27

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

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

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

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

46
    $new_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($platform, '/')));
47
    drush_invoke_process('@none', "provision-save", array($new_platform), array(
48 49 50 51
      'context_type' => 'platform',
      'server' => '@server_master',
      'web_server' => '@server_master',
      'root' => $platform,
52
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
53 54 55
    ));
    provision_backend_invoke($new_platform, 'provision-verify');
    drush_set_option('new_platform', $new_platform);
omega8cc's avatar
omega8cc committed
56
    // exit if an error has occured.
57 58 59
    if (drush_get_error()) {
      return false;
    }
60
  }
61 62 63 64
  else {

    // add a server record :
    $server = '@server_master';
65 66 67 68
    /**
     * @deprecated in drush3 it's 'options', in drush 4 it's 'cli', drop
     * 'options' when we drop drush3 support
     */
69
    $context = drush_get_context('cli') ? 'cli' : 'options';
70
    drush_invoke_process('@none', "provision-save", array($server), array(
71 72 73 74 75
      'context_type' => 'server',
      'aegir_root' => dirname(rtrim($data['config_path'], '/')),
      'remote_host' => php_uname('n'),
      'script_user' => $data['script_user'],
     // apache or nginx or..
76
      'http_service_type' => drush_get_option('http_service_type', 'apache', $context),
77 78 79 80 81 82 83
      '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'],
    ));
84

85 86
    provision_backend_invoke($server, 'provision-verify');
    drush_set_option('server_name', $server);
omega8cc's avatar
omega8cc committed
87
    // exit if an error has occured.
88 89 90
    if (drush_get_error()) {
      return false;
    }
91

omega8cc's avatar
omega8cc committed
92

93
    $old_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($data['publish_path'], '/')));
94
    drush_invoke_process('@none', "provision-save", array($old_platform), array(
95 96 97 98 99 100 101
      '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);
omega8cc's avatar
omega8cc committed
102
    // exit if an error has occured.
103 104 105 106 107
    if (drush_get_error()) {
      return false;
    }

    $new_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($platform, '/')));
108
    drush_invoke_process('@none', "provision-save", array($new_platform), array(
109 110 111 112
      'context_type' => 'platform',
      'server' => $server,
      'web_server' => $server,
      'root' => $platform,
113
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
114 115 116
    ));
    provision_backend_invoke($new_platform, 'provision-verify');
    drush_set_option('new_platform', $new_platform);
omega8cc's avatar
omega8cc committed
117
    // exit if an error has occured.
118 119 120 121 122 123
    if (drush_get_error()) {
      return false;
    }


    $site_name = '@hostmaster';
124
    drush_invoke_process('@none', "provision-save", array($site_name), array(
125 126 127 128 129
      'context_type' => 'site',
      'platform' => $old_platform,
      'db_server' => $server,
      'uri' => $site,
      'profile' => 'hostmaster',
130
      'drush_aliases' => 'hm',
131 132 133
    ));
    provision_backend_invoke($site_name, 'provision-verify');
    drush_set_option('site_name', $site_name);
omega8cc's avatar
omega8cc committed
134
    // exit if an error has occured.
135 136 137 138
    if (drush_get_error()) {
      return false;
    }
  }
139 140
}

141 142 143 144 145 146 147 148
/**
 * Prepare the hostmaster site for migration
 *
 * @deprecated most of the stuff here needs to be removed in favor of
 * hosting-pause, but since that exists only starting with rc3, we
 * need to copy the content of it here. once 1.0 is released, we can
 * remove that code and just keep hosting-pause.
 */
149
function drush_provision_pre_hostmaster_migrate($site, $platform) {
150 151
  // wipe out cron entry
  exec('crontab -r');
152 153
}

154
function drush_provision_hostmaster_migrate($site, $platform) {
Adrian Rossouw's avatar
Adrian Rossouw committed
155
  provision_backend_invoke(drush_get_option('site_name'), 'provision-migrate', array(drush_get_option('new_platform')));
156 157 158
}

function drush_provision_post_hostmaster_migrate($site, $platform) {
159
  provision_backend_invoke(drush_get_option('site_name'), 'cache-clear', array('drush'));
160 161
  // we pass the context names we generated to the task so we can enforce that the names
  // stay the same.
anarcat's avatar
anarcat committed
162
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-resume', array(), array(
163 164
    'old_platform_name' => drush_get_option('old_platform'),
    'new_platform_name' => drush_get_option('new_platform'),
Adrian Rossouw's avatar
Adrian Rossouw committed
165
  ));
166 167
}