Skip to content

Commit

Permalink
Merge pull request #1224 from DavidS/allow_no_docroot
Browse files Browse the repository at this point in the history
(MODULES-2120) Allow empty docroot
  • Loading branch information
igalic committed Oct 13, 2015
2 parents 3a1a4e4 + b63aac2 commit 6124598
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
[`logroot`]: #logroot
[Log security]: http://httpd.apache.org/docs/current/logs.html#security

[`manage_docroot`]: #manage_docroot
[`manage_user`]: #manage_user
[`manage_group`]: #manage_group
[`MaxConnectionsPerChild`]: https://httpd.apache.org/docs/current/mod/mpm_common.html#maxconnectionsperchild
Expand Down Expand Up @@ -1886,6 +1887,8 @@ Sets the list of resources to look for when a client requests an index of the di

**Required**. Sets the [`DocumentRoot`][] location, from which Apache serves files.

If `docroot` and [`manage_docroot`][] are both set to `false`, no [`DocumentRoot`][] will be set and the accompanying `<Directory /path/to/directory>` block will not be created.

##### `docroot_group`

Sets group access to the [`docroot`][] directory. Defaults to 'root'.
Expand Down
20 changes: 14 additions & 6 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@
if $limit_request_field_size {
validate_integer($limit_request_field_size)
}

# Validate the docroot as a string if:
# - $manage_docroot is true
if $manage_docroot {
validate_string($docroot)
}
# Input validation ends

if $ssl and $ensure == 'present' {
Expand Down Expand Up @@ -271,7 +277,7 @@

# This ensures that the docroot exists
# But enables it to be specified across multiple vhost resources
if ! defined(File[$docroot]) and $manage_docroot {
if $manage_docroot and $docroot and ! defined(File[$docroot]) {
file { $docroot:
ensure => directory,
owner => $docroot_owner,
Expand Down Expand Up @@ -443,7 +449,7 @@
fail("Apache::Vhost[${name}]: 'directories' must be either a Hash or an Array of Hashes")
}
$_directories = $directories
} else {
} elsif $docroot {
$_directory = {
provider => 'directory',
path => $docroot,
Expand Down Expand Up @@ -518,10 +524,12 @@
# Template uses:
# - $virtual_docroot
# - $docroot
concat::fragment { "${name}-docroot":
target => "${priority_real}${filename}.conf",
order => 10,
content => template('apache/vhost/_docroot.erb'),
if $docroot {
concat::fragment { "${name}-docroot":
target => "${priority_real}${filename}.conf",
order => 10,
content => template('apache/vhost/_docroot.erb'),
}
}

# Template uses:
Expand Down
10 changes: 10 additions & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@
it { is_expected.to_not contain_concat__fragment('rspec.example.com-limits') }
it { is_expected.to contain_concat__fragment('rspec.example.com-file_footer') }
end
context 'when not setting nor managing the docroot' do
let :params do
{
'docroot' => false,
'manage_docroot' => false,
}
end
it { is_expected.to compile }
it { is_expected.not_to contain_concat__fragment('rspec.example.com-docroot') }
end
end
describe 'access logs' do
let :facts do
Expand Down
2 changes: 1 addition & 1 deletion templates/vhost/_docroot.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
## Vhost docroot
<% if @virtual_docroot -%>
VirtualDocumentRoot "<%= @virtual_docroot %>"
<% else -%>
<% elsif @docroot -%>
DocumentRoot "<%= @docroot %>"
<% end -%>

0 comments on commit 6124598

Please sign in to comment.