apache_service.inc 4.35 KB
Newer Older
1 2 3 4 5
<?php




6 7
class provisionService_http_apache extends provisionService_http {

8
  function create_site_config() {
9 10
    $config = new provisionConfig_apache_site(drush_get_merged_options());
    return $config->write();
11 12
  }

13
  function delete_site_config() {
14 15
    $config = new provisionConfig_apache_site(drush_get_merged_options());
    return $config->unlink();
16 17 18
  }

  function create_platform_config() {
19 20
    $config = new provisionConfig_apache_platform(drush_get_merged_options());
    return $config->write();
21 22
  }

23
  function delete_platform_config() {
24 25
    $config = new provisionConfig_apache_platform(drush_get_merged_options());
    return $config->unlink();
26 27 28 29
  }


  function create_server_config() {
30 31 32 33 34
    $config = new provisionConfig_apache_server(drush_get_merged_options());
    return $config->write();
  }

  
35
  function delete_server_config() {
36 37 38
    $config = new provisionConfig_apache_server(drush_get_merged_options());
    return $config->unlink();
  }
39

40

41
  function verify() {
42 43 44 45
    if (PROVISION_CONTEXT_PLATFORM) {
      if (drush_get_option('platform', null)) {
        $this->create_platform_config();
      }
46 47
    }
    elseif (PROVISION_CONTEXT_SERVER) {
48 49 50 51
      provision_service('file')->create_dir(drush_get_option('vhost_path'), dt("Virtual host configuration"), 0700);
      provision_service('file')->create_dir(drush_get_option('platform_conf_path'), dt("Platforms configuration"), 0700);
      provision_service('file')->create_dir(drush_get_option('config_path') . '/apache.d' , dt("Apache configuration"), 0700);
 
52 53
      $this->create_server_config();
    }
54
    elseif (PROVISION_CONTEXT_SITE) {
55
      $this->create_site_config();
56 57 58 59 60 61
    }

    $this->parse_configs();
  }

  function parse_configs($cause_error = FALSE) {
drumm's avatar
drumm committed
62 63
    // This is required to be configurable, due to the fact that different
    // hosts might need to do this differently.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    $return = drush_shell_exec(escapeshellcmd(drush_get_option('restart_cmd')));
    if (!$return) {
      $msg = join("\n", drush_shell_exec_output());
      if ($cause_error) {
        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. (error: %msg)", array("%msg" => $msg)));
      }
      else {
        drush_log(dt("Web server could not be restarted. Changes might not be available until this has been done. (error: %msg)", array("%msg" => $msg)), "warning");
      }
    }
    else {
      drush_log(dt('Apache has been restarted'));
    }

    return $return;
  }


82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
}

class provisionConfig_apache extends provisionConfig {

}


class provisionConfig_apache_server extends provisionConfig_apache {
  public $template = 'server.tpl.php';
  public $description = 'apache server configuration file';

  function filename() {
    return $this->data['config_path'] . '/' . 'apache.conf';
  }

  function process() {
    $this->data['extra_config'] = "# Extra configuration from modules:\n";
    $this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_apache_server_config', $this->data));
  }
}

class provisionConfig_apache_platform extends provisionConfig_apache {
  public $template = 'platform.tpl.php';
  public $description = 'apache platform configuration file';
106

107 108 109
  function filename() {
    return $this->data['platform_conf_path'] . '/platform_' . $this->data['platform'] . '.conf';
  }
110

111 112 113
  function process() {
    $this->data['extra_config'] = "# Extra configuration from modules:\n";
    $this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_apache_dir_config', $this->data));
114
  }
115
}
116 117 118 119 120 121

class provisionConfig_apache_site extends provisionConfig_apache {
  public $template = 'vhost.tpl.php';
  public $description = 'apache site configuration file';

  function filename() {
122 123 124 125
    if (!$this->data['site_port'] || $this->data['site_port'] < 1 || $this->data['site_port'] > 66535) {
      $this->data['site_port'] = 80;
    }

126 127 128 129 130 131 132 133 134 135 136 137 138 139
    return $this->data['vhost_path'] . '/' . $this->data['site_url'] . '_' . $this->data['site_port'];
  }

  function process() {
    if ($this->data['aliases'] && !is_array($this->data['aliases'])) {
      $this->data['aliases'] = explode(",", $this->data['aliases']);
    }

    $this->data['extra_config'] = "# Extra configuration from modules:\n";
    $this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_apache_vhost_config', $this->data['site_url'], $this->data));

  }
}