migrate.hostmaster.inc 5.9 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 56 57 58 59
    // propagate working-copy args downward
    $options = array();
    if (drush_get_option('working-copy')) {
      $options['working-copy'] = 1;
    }
    provision_backend_invoke($new_platform, 'provision-verify', array(), $options);
60
    drush_set_option('new_platform', $new_platform);
omega8cc's avatar
omega8cc committed
61
    // exit if an error has occured.
62 63 64
    if (drush_get_error()) {
      return false;
    }
65
  }
66 67 68 69
  else {

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

90 91
    provision_backend_invoke($server, 'provision-verify');
    drush_set_option('server_name', $server);
omega8cc's avatar
omega8cc committed
92
    // exit if an error has occured.
93 94 95
    if (drush_get_error()) {
      return false;
    }
96

omega8cc's avatar
omega8cc committed
97

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

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


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

146 147 148
/**
 * Prepare the hostmaster site for migration
 */
149
function drush_provision_pre_hostmaster_migrate($site, $platform) {
150 151
  // we ignore errors here through integrate = FALSE
  provision_backend_invoke(drush_get_option('site_name'), 'hosting-pause', array(), array('#integrate' => FALSE));
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.
162
  provision_backend_invoke(drush_get_option('site_name'), 'hosting-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
}