install.hostmaster.inc 8.36 KB
Newer Older
1 2 3
<?php

/**
4
 * @file install the hostmaster system
5 6
 */

7
function drush_provision_hostmaster_install_validate($site = NULL) {
8 9
  // set defaults for this whole script
  // those are settings that are not prompted to the user but still overridable
10 11
  drush_set_default('version', provision_version());
  $version = drush_get_option('version');
12 13 14 15 16 17
  $aegir_root = drush_set_default('aegir_root', drush_server_home());
  drush_set_default('root', $aegir_root . '/' . 'hostmaster-' . $version);
  drush_set_default('r', drush_get_option('root'));
  drush_set_default('script_user', provision_current_user());
  drush_set_default('web_group', _provision_default_web_group());
  drush_set_default('http_service_type', 'apache');
anarcat's avatar
anarcat committed
18
  drush_set_default('aegir_db_user', 'root');
19
  drush_set_default('client_name', 'admin');
anarcat's avatar
anarcat committed
20
  $aegir_db_user = drush_get_option('aegir_db_user');
21
  drush_set_default('makefile', dirname(__FILE__) . '/aegir.make');
22

23
  drush_print("Aegir $version automated install script");
24
  drush_print("==============================================================================");
25

26
  if (!$site || !drush_get_option('aegir_host', NULL) || !drush_get_option('aegir_db_pass', NULL) || filter_var(drush_get_option('client_email'), FILTER_VALIDATE_EMAIL)) {
27
    drush_print("Some settings have not been provided and will now be prompted.
28 29 30 31
Don't worry: you will get to review those settings after the final install");
  }
  // now we prompt the user for settings if not provided or not sane
  if (!$site) {
32
    $site = drush_prompt(dt("Aegir frontend URL"), provision_fqdn());
33
  }
34
  drush_set_option('site', $site);
35

36
  drush_set_default('aegir_host', provision_fqdn());
37
  drush_set_default('aegir_db_host', 'localhost');
38 39 40 41 42 43 44 45 46

  if (is_null(drush_get_option('aegir_db_pass', NULL))) {
    // XXX: may not be portable everywhere?
    system('stty -echo');
    drush_set_option('aegir_db_pass', drush_prompt(dt('MySQL privileged user ("!root") password', array('!root' => $aegir_db_user))));
    system('stty echo');
    print "\n"; // add a newline since the user's didn't print    
  }

47
  if (drush_get_option('aegir_host') == 'localhost') {
48 49
    $default_email = 'webmaster@example.com';
  } else {
50
    $default_email = 'webmaster@' . drush_get_option('aegir_host');
51
  }
52
  drush_set_default('client_email', $default_email);
53
  while (!filter_var(drush_get_option('client_email'), FILTER_VALIDATE_EMAIL) && !drush_get_context('DRUSH_AFFIRMATIVE')) {
54
    drush_set_option('client_email', drush_prompt(dt("Admin user e-mail"), $default_email));
55 56
  }

57
  drush_print(dt('
58 59 60
This script will operate the following changes in your system:

1. Create server-level configuration directories
61 62 63
2. Create the Hostmaster frontend platform
3. Install the frontend site
4. Setup the dispatcher (a user cron job)
64 65

We are making the following assumptions:
66 67
 * you have read and are following the install instructions at:
    http://community.aegirproject.org/installing
68
 * the FQDN of this machine is valid and resolves
69
 * you are executing this script as your "aegir" user
70

71 72
The following settings will be used:
 Aegir frontend URL: !site
anarcat's avatar
anarcat committed
73
 Master server FQDN: !fqdn
74 75 76 77
 Aegir root: !home
 Aegir user: !user
 Web group: !web
 Web server: !web_server
78
 Aegir DB host: !db_host
79 80 81 82
 Aegir DB user: !db_user
 Aegir DB password: !db_pass
 Aegir version: !version
 Aegir platform path: !root
anarcat's avatar
anarcat committed
83
 Aegir makefile: !makefile
84
 Admin email: !email
85
', array('!site' => $site,
86 87 88 89 90
         '!fqdn' => drush_get_option('aegir_host'),
         '!home' => drush_get_option('aegir_root'),
         '!user' => drush_get_option('script_user'),
         '!web' => drush_get_option('web_group'),
         '!web_server' => drush_get_option('http_service_type'),
91
         '!db_host' => drush_get_option('aegir_db_host'),
92
         '!db_user' => drush_get_option('aegir_db_user'),
anarcat's avatar
anarcat committed
93
         '!db_pass' => is_null(drush_get_option('aegir_db_pass', NULL, 'process')) ? '<previously set>' : '<prompted>',
94 95
         '!version' => drush_get_option('version'),
         '!root' => drush_get_option(array('r', 'root')),
anarcat's avatar
anarcat committed
96
         '!makefile' => drush_get_option('makefile'),
97
         '!email' => drush_get_option('client_email'),
98
         )));
99

100
  if (!drush_confirm(dt('Do you really want to proceed with the install'))) {
101
    return drush_set_error('PROVISION_CANCEL_INSTALL', dt('Installation aborted'));
102
  }
103

104 105 106
  return TRUE;
}

107 108 109
/**
 * Drush command to install hostmaster.
 */
110
function drush_provision_hostmaster_install($site = NULL) {
111
  $version = drush_get_option('version');
112
  $site = drush_get_option('site', provision_fqdn());
113 114
  $aegir_root = drush_get_option('aegir_root');
  $platform = drush_get_option(array('r', 'root'));
115

116 117
  $aegir_db_user = drush_get_option('aegir_db_user');
  $aegir_db_pass = drush_get_option('aegir_db_pass');
118
  
119
  $server = '@server_master';
120
  $master_context = array(
121
    'context_type' => 'server',
122
    // files
anarcat's avatar
anarcat committed
123
    'remote_host' => drush_get_option('aegir_host'),
124
    'aegir_root' => $aegir_root,
125
    'script_user' => drush_get_option('script_user'),
126
   // apache or nginx or..
127 128
    'http_service_type' => drush_get_option('http_service_type'),
    'web_group' => drush_get_option('web_group'),
129
    'master_url' => "http://" . $site,
130 131
  );

132
  $master_db = sprintf("mysql://%s:%s@%s", urlencode($aegir_db_user), urlencode($aegir_db_pass), drush_get_option('aegir_db_host'));
133 134 135 136 137 138 139
  if (drush_get_option('aegir_host') == drush_get_option('aegir_db_host')) {
    $master_context['db_service_type'] = 'mysql';
    $master_context['master_db'] = $master_db;
    $dbserver = $server;
  } else {
    $dbserver = '@server_' . drush_get_option('aegir_db_host');
    $dbserver_context = array(
140
      'remote_host' => drush_get_option('aegir_db_host'),
141 142 143 144
      'context_type' => 'server',
      'db_service_type' => 'mysql',
      'master_db' => $master_db,
    );
145
    drush_invoke_process('@none', "provision-save", array($dbserver), $dbserver_context);
146 147
    provision_backend_invoke($dbserver, 'provision-verify');
  }
148
  drush_invoke_process('@none', "provision-save", array($server), $master_context);
149
  provision_backend_invoke($server, 'provision-verify');
150

151 152 153 154 155
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

156 157 158 159
  if (drush_get_option('backend-only')) {
    return;
  }

160
  $platform_name = '@platform_hostmaster';
161
  drush_invoke_process('@none', "provision-save", array($platform_name), array(
162 163 164
    'context_type' => 'platform',
    'server' => $server,
    'web_server' => $server,
165
    'root' => $platform,
anarcat's avatar
anarcat committed
166
    'makefile' => drush_get_option('makefile'),
167
  ));
168 169 170 171 172 173
  // propagate working-copy args downward
  $options = array();
  if (drush_get_option('working-copy')) {
    $options['working-copy'] = 1;
  }
  provision_backend_invoke($platform_name, 'provision-verify', array(), $options);
174

175 176 177 178 179
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

180 181 182
  drush_set_default('profile', 'hostmaster');
  $profile = drush_get_option('profile');

183
  $site_name = '@hostmaster';
184
  drush_invoke_process('@none', "provision-save", array($site_name), array(
185 186
    'context_type' => 'site',
    'platform' => $platform_name,
187
    'db_server' => $dbserver,
188
    'uri' => $site,
189
    'client_name' => drush_get_option('client_name'),
190
    'profile' => $profile,
191
  ));
192
  $data = provision_backend_invoke($site_name, 'provision-install', array(), array('client_email' => drush_get_option('client_email')));
193
  provision_backend_invoke($site_name, 'provision-verify');
194

195 196 197 198 199 200
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }


mig5's avatar
mig5 committed
201
  drush_print(dt("Initializing the hosting system"));
202
  drush_invoke_process('@none', 'cache-clear', array('drush'));
203
  provision_backend_invoke($site_name, 'hosting-setup');
204

205 206 207 208 209 210 211 212 213 214 215 216 217
  drush_print("");
  drush_print("==============================================================================");
  drush_print("");
  drush_print("");
  drush_print(dt("Congratulations, Aegir has now been installed."));
  drush_print("");
  drush_print(dt("You should now log in to the Aegir frontend by opening the following link in your web browser:"));
  drush_print("");
  drush_print($data['context']['login_link']);
  drush_print("");
  drush_print("");
  drush_print("==============================================================================");
  drush_print("");
218 219
}

220 221 222 223 224 225 226 227 228
/**
 *  Implements drush_hook_post_hostmaster_install().
 */
function drush_provision_post_hostmaster_install() {
  $backend_only = drush_get_option('backend-only');
  if (empty($backend_only)) {
    drush_invoke_process('@hostmaster', 'cache-clear', array('drush'));
  }
}