provision_apache.drush.inc 2.89 KB
Newer Older
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
<?php
// $Id$
/**
 * @file
 * Apache provisioning module
 * This module simply serves to generate the virtual host entry, and make sure apache gets reloaded properly.
 * Because Drupal is running via the command line for the entirety of this process, it is only necessary to make
 * it available online once everything has been completed.
 *
 * This module still requires configuration and sanity checks. Need to figure out a way to inspect the apache configuration, 
 * to ensure that the sites are getting loaded up correctly.
 */

/**
 * The default template provided for the virtual host configuration
 */
function _provision_apache_default_template() {
  return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost.tpl.php");
}

/**
 * The default template for disabled sites
 */
function _provision_apache_redirect_template() {
  return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost_redirect.tpl.php");
}

/**
 * Delete virtual host file
 */
31
32
function _provision_apache_delete_vhost_config($url) {
  provision_path("unlink", drush_get_option('vhost_path') ."/$url", TRUE, dt("Removed apache virtual host configuration"));
33
34
35
36
37
}

/**
 * Generate virtual host file
 */
38
39
function _provision_apache_create_vhost_config($url, $template = NULL) {
  $options = drush_get_merged_options();
40
  if (is_null($template)) {
41
    $template = _provision_apache_default_template();
42
  }
43
  drush_log(dt("Generate virtual host configuration file."));
44
  $writable = provision_path("writable", drush_get_option('vhost_path'), TRUE , NULL,
45
      dt("Virtual host configuration path @path is not writable."), 
46
      PROVISION_VHOST_PATH_NOT_WRITABLE);
47
  $options['extra_config'] = "# Extra configuration from modules:\n";
48
  foreach (drush_command_implements('provision_vhost_config') as $module) {
49
50
    $options['extra_config'] .= "# -- $module settings --\n";
    $options['extra_config'] .= module_invoke($module, 'provision_vhost_config', $url, $options) . "\n";
51
52
53
  }
  
  if ($writable) {
54
55
    $file = fopen(drush_get_option('vhost_path') .'/'. $url, "w");
    $text = provision_render_config($template, $options);
56
57
58
59
60
61
62
63
64
65
66
    fwrite($file, $text);
    fclose($file);
  }
}
 
/**
 * Restart Apache
 */
function _provision_apache_restart_apache($cause_error = FALSE) {
  //This is required to be configurable, due to the fact that different hosts might need to do this differently.
  //TODO : test for this instead of relying on a configuration setting?
67
  $return = drush_shell_exec(escapeshellcmd(drush_get_option('restart_cmd')));
68
69
  if (!$return) {
    if ($cause_error) {
70
      return drush_set_error(PROVISION_WEB_RESTART_FAILED, dt("Web server could not be restarted. Changes might not be available until this has been done."));
71
72
73
    }
    else {
      drush_log(dt("Web server could not be restarted. Changes might not be available until this has been done."), "warning");
74
75
76
    }
  }
  else {
77
    drush_log(dt('Apache has been restarted'));
78
79
  }

80
  return $return;
81
82
}