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

/**
 * @file manual site migrate system
 */

function drush_provision_hostmaster_migrate_validate($site, $platform) {
  // verify the target platform:
9 10 11 12 13 14 15 16 17
  if (!is_dir($platform)) {
    drush_print("The platform path you specified does not exist yet.");
    drush_print("Downloading the hostmaster front end. (this might take a few minutes)");
    drush_backend_invoke('make', array(dirname(__FILE__) . '/aegir.make', $platform));
    if (drush_get_error()) {
      drush_log("The hostmaster front end could not be downloaded, exiting.", "error");
    }
  }

18 19
  $data = drush_get_merged_options();
  // add a server record :
20
  $server = '@server_localhost';
21 22 23 24 25 26 27
  drush_backend_invoke_args("provision-save", array($server), array(
    'context_type' => 'server',
   // files
    'file_service_type' => 'local',
    'aegir_root' => dirname(rtrim($data['config_path'], '/')),
    'config_path' => $data['config_path'],
    'backup_path' => $data['backup_path'],
28
    'script_user' => $data['script_user'],
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
   // apache 
    'http_service_type' => 'apache',
    '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);

  $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);

  $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,
  ));
  provision_backend_invoke($new_platform, 'provision-verify');
  drush_set_option('new_platform', $new_platform);

62
  $site_name = '@hostmaster';
63 64 65 66 67 68 69 70 71
  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);
72 73
}

74

75
function drush_provision_pre_hostmaster_migrate($site, $platform) {
76
  if (!drush_confirm("This command will replace your crontab entry. continue?")) {
77
    return drush_set_error('PROVISION_CANCEL_MIGRATE', 'Cancelling');
78 79 80 81 82
  }
  // wipe out cron entry
  exec('crontab -r');

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

86 87
function drush_provision_hostmaster_migrate($site, $platform) {
  provision_backend_invoke(drush_get_option('site_name'), 'provision-migrate', drush_get_option('new_platform'));
88 89 90
}

function drush_provision_post_hostmaster_migrate($site, $platform) {
91 92
  // 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
93
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-resume', array(), array( 
94 95
    'old_platform_name' => drush_get_option('old_platform'),
    'new_platform_name' => drush_get_option('new_platform'),
Adrian Rossouw's avatar
Adrian Rossouw committed
96
  ));
97 98
}