migrate.hostmaster.inc 3.4 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
  $data = drush_get_merged_options();
  // add a server record :
9
  $server = '@server_master';
10 11 12
  drush_backend_invoke_args("provision-save", array($server), array(
    'context_type' => 'server',
    'aegir_root' => dirname(rtrim($data['config_path'], '/')),
13
    'script_user' => $data['script_user'],
14 15 16 17 18 19 20 21 22
   // 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'],
  ));
23

24 25
  provision_backend_invoke($server, 'provision-verify');
  drush_set_option('server_name', $server);
26 27 28 29
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }
30

31
 
32 33 34 35 36 37 38 39 40
  $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);
41 42 43 44 45
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

46 47
  // dereference relative paths and symlinks
  $platform = realpath($plaform);
48 49 50 51 52 53
  $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,
54
    'makefile' => dirname(__FILE__) . '/aegir.make',
55 56 57
  ));
  provision_backend_invoke($new_platform, 'provision-verify');
  drush_set_option('new_platform', $new_platform);
58 59 60 61 62
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

63

64
  $site_name = '@hostmaster';
65 66 67 68 69 70 71 72 73
  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);
74 75 76 77 78 79
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }


80 81
}

82

83
function drush_provision_pre_hostmaster_migrate($site, $platform) {
84
  if (!drush_confirm("This command will replace your crontab entry. continue?")) {
85
    return drush_set_error('PROVISION_CANCEL_MIGRATE', 'Cancelling');
86 87 88 89 90
  }
  // wipe out cron entry
  exec('crontab -r');

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

94
function drush_provision_hostmaster_migrate($site, $platform) {
Adrian Rossouw's avatar
Adrian Rossouw committed
95
  provision_backend_invoke(drush_get_option('site_name'), 'provision-migrate', array(drush_get_option('new_platform')));
96 97 98
}

function drush_provision_post_hostmaster_migrate($site, $platform) {
99 100
  // 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
101
  provision_backend_invoke(drush_get_option('site_name'), 'hostmaster-resume', array(), array( 
102 103
    'old_platform_name' => drush_get_option('old_platform'),
    'new_platform_name' => drush_get_option('new_platform'),
Adrian Rossouw's avatar
Adrian Rossouw committed
104
  ));
105 106
}