Skip to content

Commit cdbef5a

Browse files
jaymzhfacebook-github-bot
authored andcommitted
Fix fb_apache for Debian-family (facebook#245)
Test Plan: Confirmed no changes on CentOS: P1698345753 No Debian running in prod Differential Revision: D66515561 fbshipit-source-id: d859a941a881ad3c2c68dc9138400eaa2b7cc919
1 parent 68d7b77 commit cdbef5a

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

cookbooks/fb_apache/recipes/default.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
when 'ubuntu'
4747
node['platform_version'].to_f >= 13.10 ? '2.4' : '2.2'
4848
when 'debian'
49-
node['platform_version'].to_f >= 8.0 ? '2.4' : '2.2'
49+
if node['platform_version'].end_with?('/sid')
50+
'2.4'
51+
else
52+
node['platform_version'].to_f >= 8.0 ? '2.4' : '2.2'
53+
end
5054
else
5155
'2.4'
5256
end

cookbooks/fb_apache/resources/verify_configs.rb

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,41 @@
1616
# configurations in the same and then run validator on it. This way,
1717
# validation happens on new configurations without touching the live ones.
1818
::Dir.mktmpdir do |tdir|
19-
Chef::Log.
20-
debug("fb_apache: copy from '#{new_resource.httpdir}' to '#{tdir}'")
19+
Chef::Log.debug(
20+
"fb_apache: copy from '#{new_resource.httpdir}' to '#{tdir}'",
21+
)
2122
FileUtils.cp_r("#{new_resource.httpdir}/.", tdir)
2223

2324
# This is some trickery. We change the "ServerRoot" to the temp
2425
# folder we created.
2526
#
26-
# Context - `httpd.conf` is the main config that loads other modules and
27-
# configs. `httpd.conf` lives in the canonical location called "server
28-
# root". `httpd` cli allows one to change server root using `-d` option,
29-
# however that only changes the location of where it finds `httd.conf`; it
30-
# does not change the paths from which "other" configs are loaded. To really
31-
# change the paths where other configs are loaded we have to change the
32-
# "ServerRoot" in `httpd.conf` from the canonical `/etc/httpd` to
27+
28+
# Context - `httpd.conf` (or `apache2.conf`) is the main config that loads
29+
# other modules and configs. It lives in the canonical location called
30+
# "server root". `httpd` cli allows one to change server root using `-d`
31+
# option, however that only changes the location of where it finds the
32+
# config; it does not change the paths from which "other" configs are
33+
# loaded. To really change the paths where other configs are loaded we have
34+
# to change the "ServerRoot" in the config from the canonical directory to
3335
# `/tmp/<whatever>`. This way, all the other configurations in the temp
3436
# folder are correctly loaded and verified.
3537
Chef::Log.debug("fb_apache: modify contents of '#{tdir}/conf/httpd.conf'")
36-
file = Chef::Util::FileEdit.new("#{tdir}/conf/httpd.conf")
37-
file.search_file_replace_line(%r{^ServerRoot "/etc/httpd"$},
38-
"ServerRoot \"#{tdir}\"") ||
38+
config_file = value_for_platform_family(
39+
['rhel', 'fedora'] => 'conf/httpd.conf',
40+
'debian' => 'apache2.conf',
41+
)
42+
file = Chef::Util::FileEdit.new("#{tdir}/#{config_file}")
43+
# If it's specified, change it, otherwise, change the commented-out
44+
# version (if it's the default, it stays commented out), and un-comment
45+
# it out.
46+
file.search_file_replace_line(
47+
/^ServerRoot "#{new_resource.httpdir}"$/,
48+
"ServerRoot \"#{tdir}\"",
49+
) ||
50+
file.search_file_replace_line(
51+
/^#ServerRoot "#{new_resource.httpdir}"$/,
52+
"ServerRoot \"#{tdir}\"",
53+
) ||
3954
fail('Apache validation failed. Cannot find `ServerRoot /etc/httpd`')
4055
file.write_file
4156

0 commit comments

Comments
 (0)