Skip to content

Commit

Permalink
Fix fb_apache for Debian-family
Browse files Browse the repository at this point in the history
The `verify_configs` custom resource wasn't using the passed-in httpdir
and was assuming RHEL-like httpdir and config file name. Fixed both.

Also, on Debian sid, the version-matching failed, so fixed that.

Signed-off-by: Phil Dibowitz <phil@ipom.com>
  • Loading branch information
jaymzh committed Nov 14, 2024
1 parent 08ffacf commit cb8fee2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cookbooks/fb_apache/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
when 'ubuntu'
node['platform_version'].to_f >= 13.10 ? '2.4' : '2.2'
when 'debian'
node['platform_version'].to_f >= 8.0 ? '2.4' : '2.2'
if node['platform_version'].end_with?('/sid')
'2.4'
else
node['platform_version'].to_f >= 8.0 ? '2.4' : '2.2'
end
else
'2.4'
end
Expand Down
21 changes: 16 additions & 5 deletions cookbooks/fb_apache/resources/verify_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# configurations in the same and then run validator on it. This way,
# validation happens on new configurations without touching the live ones.
::Dir.mktmpdir do |tdir|
Chef::Log.
debug("fb_apache: copy from '#{new_resource.httpdir}' to '#{tdir}'")
Chef::Log.debug(
"fb_apache: copy from '#{new_resource.httpdir}' to '#{tdir}'"
)
FileUtils.cp_r("#{new_resource.httpdir}/.", tdir)

# This is some trickery. We change the "ServerRoot" to the temp
Expand All @@ -33,9 +34,19 @@
# `/tmp/<whatever>`. This way, all the other configurations in the temp
# folder are correctly loaded and verified.
Chef::Log.debug("fb_apache: modify contents of '#{tdir}/conf/httpd.conf'")
file = Chef::Util::FileEdit.new("#{tdir}/conf/httpd.conf")
file.search_file_replace_line(%r{^ServerRoot "/etc/httpd"$},
"ServerRoot \"#{tdir}\"") ||
config_file = value_for_platform_family(
['rhel', 'fedora'] => 'conf/httpd.conf',
'debian' => 'apache2.conf',
)
file = Chef::Util::FileEdit.new("#{tdir}/#{config_file}")
file.search_file_replace_line(
%r{^ServerRoot "#{new_resource.httpdir}"$},
"ServerRoot \"#{tdir}\""
) ||
file.search_file_replace_line(
%r{^#ServerRoot "#{new_resource.httpdir}"$},
"ServerRoot \"#{tdir}\""
) ||
fail('Apache validation failed. Cannot find `ServerRoot /etc/httpd`')
file.write_file

Expand Down

0 comments on commit cb8fee2

Please sign in to comment.