Class: PoolParty::Resources::Apache

Inherits:
PoolParty::Resource show all
Defined in:
lib/poolparty/plugins/apache.rb

Direct Known Subclasses

VirtualHost

Instance Attribute Summary

Attributes inherited from PoolParty::Resource

#exists, #graph_index, #meta_not_if, #meta_notifies, #meta_only_if, #meta_subscribes

Attributes inherited from Base

#base_name, #init_opts

Instance Method Summary collapse

Methods inherited from PoolParty::Resource

#after_compile, #after_loaded, #before_compile, #case_of, #cloud, #compile, define_resource, define_resource_methods, defined, defined_resources, #does_not_exist!, #exists!, #has_method_name, has_method_name, inherited, #initialize, method_defined!, method_defined?, #not_if, #notifies, #only_if, #pool, #print_to_chef, #print_variable, #requires, #subscribes

Methods inherited from Base

#add_ordered_resources_to_result, #after_loaded, #all_resources, clouds_dot_rb_dir, #clouds_dot_rb_dir, clouds_dot_rb_file, #clouds_dot_rb_file, #compile_opts, #create_graph, #dependencies, #get_resource, #has_searchable_paths, #initialize, #method_missing, #ordered_resources, #output_resources_graph, #resources, #resources_graph, #run_in_context, #run_with_callbacks, #to_s, #valid?, #validations

Methods included from Delayed

included

Methods included from Callbacks

included

Methods included from SearchablePaths

included

Constructor Details

This class inherits a constructor from PoolParty::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PoolParty::Base

Instance Method Details

#absent_apache_module(*names) ⇒ Object



188
189
190
191
192
193
194
195
196
197
# File 'lib/poolparty/plugins/apache.rb', line 188

def absent_apache_module(*names)
  names.each do |name|
    has_exec({:name => "no-mod-#{name}"}, :command => "/usr/sbin/a2dismod #{name}") do
      requires get_package("apache2")
      not_if "/bin/sh -c \'[ -L /etc/apache2/mods-enabled/#{name}.load ] && [ /etc/apache2/mods-enabled/#{name}.load -ef /etc/apache2/mods-available/#{name}.load ]\'"
      notifies get_exec("force-reload-apache2"), :run
      requires get_exec("force-reload-apache2")
    end
  end
end

#apache_configsObject



124
125
126
# File 'lib/poolparty/plugins/apache.rb', line 124

def apache_configs
  has_chef_attributes_file PoolParty.lib_dir/"vendor"/"chef"/"apache2"/"attributes"/"apache.rb"
end

#base_installObject



29
30
31
32
33
34
35
36
# File 'lib/poolparty/plugins/apache.rb', line 29

def base_install
  unless @base_install
    has_exec({:name => "restart-apache2", :command => "/etc/init.d/apache2 restart", :action => :nothing})
    has_exec({:name => "reload-apache2", :command => "/etc/init.d/apache2 reload", :action => :nothing, :requires => get_package("apache2")})
    has_exec({:name => "force-reload-apache2", :command => "/etc/init.d/apache2 force-reload", :action => :nothing})
    @base_install = true
  end
end

#before_loadObject



12
13
14
15
16
17
18
# File 'lib/poolparty/plugins/apache.rb', line 12

def before_load
  installed_as_worker
  configs
  has_service("apache2", :requires => get_package("apache2"))
  has_user "www-data"
  apache_configs
end

#config(name, temp) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/poolparty/plugins/apache.rb', line 133

def config(name, temp)
  has_file(:name => "/etc/apache2/conf.d/#{name}.conf") do
    template File.dirname(__FILE__)/temp
    notifies get_exec("reload-apache2"), :run
    requires get_exec("reload-apache2")
  end
end

#configsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/poolparty/plugins/apache.rb', line 91

def configs
  unless @configs
    listen(port) unless @listen
    has_directory("#{www_dir}", :mode => "0755")
    has_directory("/etc/apache2")
    has_directory("/etc/apache2/conf.d")
    has_directory("/etc/apache2/site-includes")
    
    has_file("/etc/apache2/apache2.conf") do
      mode 0644
      requires get_directory("/etc/apache2/conf.d")
      requires get_package("apache2")
      template File.dirname(__FILE__)/"apache2"/"apache2.conf.erb"
    end
    # does_not_have_file(:name => "/etc/apache2/ports.conf")
    
    has_exec("/usr/sbin/a2dissite default") do
      only_if "/usr/bin/test -L /etc/apache2/sites-enabled/000-default"
      notifies get_exec("reload-apache2"), :run
      requires get_exec("reload-apache2")
    end
    
    # Base config
    config("base",          "apache2"/"base.conf.erb")
    config("mime",          "apache2"/"mime-minimal.conf.erb")
    config("browser_fixes", "apache2"/"browser_fixes.conf.erb")
    
    present_apache_module("mime", "rewrite")
  # end
    @configs = true
  end
end

#enable_defaultObject



128
129
130
131
# File 'lib/poolparty/plugins/apache.rb', line 128

def enable_default
  listen 80 # assumes no haproxy
  site "default-site", :template => File.dirname(__FILE__)/:apache2/"default-site.conf.erb"
end

#enable_passengerObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/poolparty/plugins/apache.rb', line 43

def enable_passenger
  unless @enable_passenger
    installed_as_worker
    has_package     "build-essential"
    has_package     "apache2-prefork-dev"
    has_gem_package "fastthread"
    has_gem_package "passenger"
    passenger_configs
    
    has_exec "install_passenger_script" do
      command "passenger-install-apache2-module --auto"
      notifies get_exec("restart-apache2"), :run
      requires get_exec("restart-apache2")
      requires get_package("apache2")
      requires get_gem_package("passenger")
      not_if "test -f /etc/apache2/mods-available/passenger.conf && test -s /etc/apache2/mods-available/passenger.conf "
      creates lambda { "@node[:apache][:passenger_module_path]" }
      end
    
    @enable_passenger = true
  end
end

#install_passengerObject



39
40
41
# File 'lib/poolparty/plugins/apache.rb', line 39

def install_passenger
  enable_passenger
end

#install_site(name, opts = {}) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/poolparty/plugins/apache.rb', line 159

def install_site(name, opts={})
  sitename = name

  opts.merge!(:name => "/etc/apache2/sites-available/#{sitename}")
  has_directory(:name => "/etc/apache2/sites-available")
  has_file(opts) unless opts[:no_file]
  has_exec(:name => "/usr/sbin/a2ensite #{sitename}") do
    notifies get_exec("reload-apache2"), :run
    requires get_exec("reload-apache2")
    requires get_file("/etc/apache2/sites-available/#{sitename}")
    not_if "/bin/sh -c '[ -L /etc/apache2/sites-enabled/#{sitename} ] && [ /etc/apache2/sites-enabled/#{sitename} -ef /etc/apache2/sites-available/#{sitename} ]'"
  end
end

#installed_as_workerObject



20
21
22
23
24
25
26
27
# File 'lib/poolparty/plugins/apache.rb', line 20

def installed_as_worker
  unless @installed_as_worker
    has_package("apache2")
    
    base_install
    @installed_as_worker = true
  end
end

#listen(p = "80") ⇒ Object



141
142
143
144
145
# File 'lib/poolparty/plugins/apache.rb', line 141

def listen(p="80")
  has_variable(:name => "port", :value => [p])
  self.port = p
  @listen = true
end

#passenger_configsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/poolparty/plugins/apache.rb', line 66

def passenger_configs
  unless @passenger_configs
    
    has_variable("passenger_version",     passenger_version)
    has_variable("passenger_root_path",   "\#{languages[:ruby][:gems_dir]}/gems/passenger-#{passenger_version}")
    has_variable("passenger_module_path", "\#{passenger_site[:passenger_root_path]}/ext/apache2/mod_passenger.so")
    
    has_file(:name => "/etc/apache2/mods-available/passenger.load") do
      content "LoadModule passenger_module <%= @node[:passenger_site][:passenger_module_path] %>\n      eof\n    end\n    \n    has_file(:name => \"/etc/apache2/mods-available/passenger.conf\") do\n      content <<-eof\nPassengerRoot <%= @node[:passenger_site][:passenger_root_path] %>\nPassengerRuby <%= @node[:languages][:ruby][:ruby_bin] %>\n      eof\n    end\n    \n    present_apache_module(:passenger)\n    @passenger_configs = true\n  end\nend\n"

#present_apache_module(*names) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/poolparty/plugins/apache.rb', line 177

def present_apache_module(*names)
  names.each do |name|
    has_exec(:name => "mod-#{name}", :command => "/usr/sbin/a2enmod #{name}") do            
      not_if "/bin/sh -c \'[ -L /etc/apache2/mods-enabled/#{name}.load ] && [ /etc/apache2/mods-enabled/#{name}.load -ef /etc/apache2/mods-available/#{name}.load ]\'"
      requires get_package("apache2")
      notifies get_exec("force-reload-apache2"), :run
      requires get_exec("force-reload-apache2")
    end
  end
end

#site(name, opts = {}) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/poolparty/plugins/apache.rb', line 147

def site(name, opts={})
  if exists?
    install_site(name, opts)
  else
    has_exec(:command => "/usr/sbin/a2dissite #{name}") do
      notifies get_exec("reload-apache2"), :run
      requires get_package("apache2")
      only_if "/bin/sh -c \"[ -L /etc/apache2/sites-enabled/#{name} ] && [ /etc/apache2/sites-enabled/#{name} -ef /etc/apache2/sites-available/#{name}]\""
    end
  end
end

#site_include(name, content, ensureer = "present") ⇒ Object



173
174
175
# File 'lib/poolparty/plugins/apache.rb', line 173

def site_include(name, content, ensureer="present")
  has_file(:name => "/etc/apache2/site-includes/#{name}.inc", :ensures => ensureer, :content => content, :requires => get_file("/etc/apache2/site-includes"))
end