Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fb_apache for Debian-family #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 27 additions & 12 deletions cookbooks/fb_apache/resources/verify_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,41 @@
# 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
# folder we created.
#
# Context - `httpd.conf` is the main config that loads other modules and
# configs. `httpd.conf` lives in the canonical location called "server
# root". `httpd` cli allows one to change server root using `-d` option,
# however that only changes the location of where it finds `httd.conf`; it
# does not change the paths from which "other" configs are loaded. To really
# change the paths where other configs are loaded we have to change the
# "ServerRoot" in `httpd.conf` from the canonical `/etc/httpd` to

# Context - `httpd.conf` (or `apache2.conf`) is the main config that loads
# other modules and configs. It lives in the canonical location called
# "server root". `httpd` cli allows one to change server root using `-d`
# option, however that only changes the location of where it finds the
# config; it does not change the paths from which "other" configs are
# loaded. To really change the paths where other configs are loaded we have
# to change the "ServerRoot" in the config from the canonical directory to
# `/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}")
# If it's specified, change it, otherwise, change the commented-out
# version (if it's the default, it stays commented out), and un-comment
# it out.
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
Loading