Class: PoolParty::Plugin::Apache
- Inherits:
-
Plugin
show all
- Defined in:
- lib/poolparty/plugins/apache2/apache.rb
Overview
Install Apache2 and make various helpers accessible.
NOTE: this will not install a virtual host by default, including a default host. This means apache will not start up unless you specify at least the default host.
Instance Attribute Summary
#init_opts, #ordered_resources
Instance Method Summary
collapse
Methods inherited from Plugin
#after_create, #bootstrap_commands, #bootstrap_gems, #calls, #cloud, #configure_commands, inherited, #initialize, #is_plugin?
Methods included from Callbacks
included
#to_properties_hash
#dependency_resolver, #instances, #plugin_directory, #run_stored_block, #store_block, #stored_block, #using
Methods inherited from Service
add_has_and_does_not_have_methods_for, #cloud, #to_properties_hash
add_has_and_does_not_have_methods_for, #add_resource, add_resource_lookup_method, #add_service, #add_to_parent_if_parent_exists_and_is_a_service, #get_local_resource, #get_name_from_options_and_extra_options, #get_resource, #handle_option_values, #in_local_resources?, #initialize, #inspect, #is_a_resource?, #is_plugin?, #plugin_store, #resource, #resources, #run_in_context, #run_with_callbacks, #search_in_known_locations, #store_in_local_resources, #to_hash, #to_json
included
Instance Method Details
#absent_apache_module(*names) ⇒ Object
209
210
211
212
213
214
215
216
217
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 209
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")
if_not "/bin/sh -c \'[ -L /etc/apache2/mods-enabled/#{name}.load ] && [ /etc/apache2/mods-enabled/#{name}.load -ef /etc/apache2/mods-available/#{name}.load ]\'"
calls get_exec("force-reload-apache2")
end
end
end
|
#base_install ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 46
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})
has_exec({:name => "force-reload-apache2", :command => "/etc/init.d/apache2 force-reload", :action => :nothing})
@base_install = true
end
end
|
#before_load(o = {}, &block) ⇒ Object
28
29
30
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 28
def before_load(o={}, &block)
install
end
|
#config(name, temp) ⇒ Object
160
161
162
163
164
165
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 160
def config(name, temp)
has_file(:name => "/etc/apache2/conf.d/#{name}.conf") do
template temp
calls get_exec("reload-apache2")
end
end
|
has_exec(:command => “a2enmod ssl”) do
requires [ get_package("openssl") ]
if_not "/usr/bin/test -L /etc/apache2/mods-enabled/ssl.load"
calls get_exec("restart-apache2")
end
@enable_ssl = true
end
end# }}}
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 124
def configs
unless @configs
listen(port) unless @listen
has_directory("/etc/apache2")
has_directory("/etc/apache2/conf.d")
has_directory("/etc/apache2/site-includes")
has_file(:name => "/etc/apache2/apache2.conf") do
mode 0644
requires get_directory("/etc/apache2/conf.d")
template "apache2"/"apache2.conf"
end
has_exec(:command => "/usr/sbin/a2dissite default") do
only_if "/usr/bin/test -L /etc/apache2/sites-enabled/000-default"
calls get_exec("reload-apache2")
end
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")
@configs = true
end
end
|
24
25
26
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 24
def enable
enable_default
end
|
#enable_default ⇒ Object
154
155
156
157
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 154
def enable_default
listen 80 site "default-site", :template => :apache2/"default-site.conf.erb"
end
|
#enable_passenger ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 60
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(:name => "install_passenger_script",
:command => 'echo -en \"\\\\n\\\\n\\\\n\\\\n\" | passenger-install-apache2-module',
:if_not => "test -f /etc/apache2/conf.d/passenger.conf && test -s /etc/apache2/conf.d/passenger.conf",
:creates => lambda { "node[:poolparty][:passenger_module_path]" },
:calls => get_exec("restart-apache2")
)
@enable_passenger = true
end
end
|
32
33
34
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 32
def install
installed_as_worker
end
|
#install_passenger ⇒ Object
55
56
57
58
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 55
def install_passenger install
enable_passenger
end
|
#install_site(name, opts = {}) ⇒ Object
185
186
187
188
189
190
191
192
193
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 185
def install_site(name, opts={})
opts.merge!(:name => "/etc/apache2/sites-available/#{name}")
has_directory(:name => "/etc/apache2/sites-available")
has_file(opts) unless opts[:no_file]
has_exec(:name => "/usr/sbin/a2ensite #{name}", :calls => get_exec("reload-apache2")) do
requires get_package("apache2")
if_not "/bin/sh -c '[ -L /etc/apache2/sites-enabled/#{name} ] && [ /etc/apache2/sites-enabled/#{name} -ef /etc/apache2/sites-available/#{name} ]'"
end
end
|
#installed_as_worker ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 36
def installed_as_worker
unless @installed_as_worker
has_package("apache2")
base_install
@installed_as_worker = true
end
end
|
#listen(p = "80") ⇒ Object
167
168
169
170
171
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 167
def listen(p="80")
has_variable(:name => "port", :value => p)
self.port = p
@listen = true
end
|
#loaded(opts = {}, &block) ⇒ Object
19
20
21
22
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 19
def loaded(opts={}, &block)
configs
has_service("apache2", :requires => get_package("apache2"))
end
|
#passenger_configs ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 80
def passenger_configs
unless @passenger_configs
has_variable "gems_path", :value => lambda { "`gem env gemdir`.chomp!" }
has_variable "ruby_path", :value => lambda { "`which ruby`.chomp!" }
passenger_version ||= "2.2.2"
has_variable("passenger_version", :value => passenger_version)
has_variable("passenger_root_path", :value => "\#{poolparty[:gems_path]}/gems/passenger-#{passenger_version}")
has_variable("passenger_module_path", :value => "\#{poolparty[:passenger_root_path]}/ext/apache2/mod_passenger.so")
has_file(:name => "/etc/apache2/mods-available/passenger.load") do
content <<-eof
LoadModule passenger_module <%= @node[:poolparty][:passenger_module_path] %>
eof
end
has_file(:name => "/etc/apache2/mods-available/passenger.conf") do
content <<-eof
PassengerRoot <%= @node[:poolparty][:passenger_root_path] %>
PassengerRuby <%= @node[:poolparty][:ruby_path] %>
eof
end
present_apache_module(:passenger)
@passenger_configs = true
end
end
|
#present_apache_module(*names) ⇒ Object
199
200
201
202
203
204
205
206
207
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 199
def present_apache_module(*names)
names.each do |name|
has_exec(:name => "mod-#{name}", :command => "/usr/sbin/a2enmod #{name}") do
requires get_package("apache2")
if_not "/bin/sh -c \'[ -L /etc/apache2/mods-enabled/#{name}.load ] && [ /etc/apache2/mods-enabled/#{name}.load -ef /etc/apache2/mods-available/#{name}.load ]\'"
calls get_exec("force-reload-apache2")
end
end
end
|
#site(name, opts = {}) ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 173
def site(name, opts={})
case opts[:ensure] || "present"
when "present", "installed"
install_site(name, opts)
when "absent"
has_exec(:command => "/usr/sbin/a2dissite #{name}", :calls => get_exec("reload-apache2")) do
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
195
196
197
|
# File 'lib/poolparty/plugins/apache2/apache.rb', line 195
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
|