|
16 | 16 | # configurations in the same and then run validator on it. This way, |
17 | 17 | # validation happens on new configurations without touching the live ones. |
18 | 18 | ::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 | + ) |
21 | 22 | FileUtils.cp_r("#{new_resource.httpdir}/.", tdir) |
22 | 23 |
|
23 | 24 | # This is some trickery. We change the "ServerRoot" to the temp |
24 | 25 | # folder we created. |
25 | 26 | # |
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 |
33 | 35 | # `/tmp/<whatever>`. This way, all the other configurations in the temp |
34 | 36 | # folder are correctly loaded and verified. |
35 | 37 | 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 | + ) || |
39 | 54 | fail('Apache validation failed. Cannot find `ServerRoot /etc/httpd`') |
40 | 55 | file.write_file |
41 | 56 |
|
|
0 commit comments