summaryrefslogtreecommitdiffstats
path: root/migrate.hostmaster.inc
blob: 66fa542b508323e599f9cbb8aa15bf2fb55d9324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php

/**
 * @file manual site migrate system
 */
function drush_provision_hostmaster_migrate_validate($site, $platform) {
  // 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 queue (hosting-pause)
4. attempt a migration to the new platform (provision-migrate)
5. start the queue (hosting-resume)

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

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

  $data = drush_get_merged_options();

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

  if (!file_exists($platform)) {
    $dir = realpath(dirname($platform));
    if (is_dir($dir)) {
      $platform = $dir . '/' . basename($platform);
      drush_log("changed relative platform path to absolute");
    }
  }

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

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

    $new_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($platform, '/')));
    drush_invoke_process('@none', "provision-save", array($new_platform), array(
      'context_type' => 'platform',
      'server' => '@server_master',
      'web_server' => '@server_master',
      'root' => $platform,
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
    ));
    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;
    }
  }
  else {

    // add a server record :
    $server = '@server_master';
    /**
     * @deprecated in drush3 it's 'options', in drush 4 it's 'cli', drop
     * 'options' when we drop drush3 support
     */
    $context = drush_get_context('cli') ? 'cli' : 'options';
    drush_invoke_process('@none', "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', $context),
      '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'],
    ));

    provision_backend_invoke($server, 'provision-verify');
    drush_set_option('server_name', $server);
    // exit if an error has occured. 
    if (drush_get_error()) {
      return false;
    }

   
    $old_platform = '@platform_' . preg_replace("/[!\W]/", "", basename(rtrim($data['publish_path'], '/')));
    drush_invoke_process('@none', "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_invoke_process('@none', "provision-save", array($new_platform), array(
      'context_type' => 'platform',
      'server' => $server,
      'web_server' => $server,
      'root' => $platform,
      'makefile' => drush_get_option('makefile', dirname(__FILE__) . '/aegir.make'),
    ));
    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_invoke_process('@none', "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;
    }
  }
}

/**
 * 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.
 */
function drush_provision_pre_hostmaster_migrate($site, $platform) {
  // wipe out cron entry
  exec('crontab -r');
}

function drush_provision_hostmaster_migrate($site, $platform) {
  provision_backend_invoke(drush_get_option('site_name'), 'provision-migrate', array(drush_get_option('new_platform')));
}

function drush_provision_post_hostmaster_migrate($site, $platform) {
  provision_backend_invoke(drush_get_option('site_name'), 'cache-clear', array('drush'));
  // we pass the context names we generated to the task so we can enforce that the names
  // stay the same.
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-resume', array(), array(
    'old_platform_name' => drush_get_option('old_platform'),
    'new_platform_name' => drush_get_option('new_platform'),
  ));
}