Skip to content

Commit

Permalink
Merge pull request #129 from hunner/access-log-flag
Browse files Browse the repository at this point in the history
Access log flag
  • Loading branch information
hunner committed Dec 13, 2012
2 parents dc11bfd + 799c32e commit 4ffb572
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
14 changes: 14 additions & 0 deletions manifests/vhost.pp
Expand Up @@ -20,6 +20,7 @@
# - The $vhost_name for name based virtualhosting, defaulting to *
# - The $logroot specifies the location of the virtual hosts logfiles, default
# to /var/log/<apache log location>/
# - The $access_log specifies if *_access.log directives should be configured.
# - The $ensure specifies if vhost file is present or absent.
#
# Actions:
Expand Down Expand Up @@ -54,6 +55,7 @@
$apache_name = $apache::params::apache_name,
$vhost_name = $apache::params::vhost_name,
$logroot = "/var/log/$apache::params::apache_name",
$access_log = true,
$ensure = 'present'
) {

Expand Down Expand Up @@ -97,6 +99,18 @@
}
}

# Template uses:
# - $vhost_name
# - $port
# - $srvname
# - $serveradmin
# - $serveraliases
# - $docroot
# - $options
# - $override
# - $logroot
# - $access_log
# - $name
file { "${priority}-${name}.conf":
ensure => $ensure,
path => "${apache::params::vdir}/${priority}-${name}.conf",
Expand Down
14 changes: 14 additions & 0 deletions manifests/vhost/proxy.pp
Expand Up @@ -9,6 +9,7 @@
# URI that the requests will be proxied for
# - $priority
# - $template -- the template to use for the vhost
# - $access_log - specifies if *_access.log directives should be configured.
# - $vhost_name - the name to use for the vhost, defaults to '*'
#
# Actions:
Expand All @@ -27,6 +28,7 @@
$serveraliases = '',
$ssl = false,
$vhost_name = '*',
$access_log = true,
$no_proxy_uris = []
) {

Expand All @@ -45,6 +47,18 @@
include apache::mod::ssl
}

# Template uses:
# - $vhost_name
# - $port
# - $ssl
# - $ssl_path
# - $srvname
# - $serveraliases
# - $no_proxy_uris
# - $dest
# - $apache::params::apache_name
# - $access_log
# - $name
file { "${priority}-${name}.conf":
path => "${apache::params::vdir}/${priority}-${name}.conf",
content => template($template),
Expand Down
16 changes: 15 additions & 1 deletion spec/defines/vhost/proxy_spec.rb
Expand Up @@ -30,7 +30,8 @@
:dest => 'example2.com',
:servername => 'example3.com',
:port => '80',
:ssl => true
:ssl => true,
:access_log => false,
},
].each do |param_set|

Expand Down Expand Up @@ -70,5 +71,18 @@
] )
end
end

[true,false].each do |value|
describe "when access_log is #{value}" do
let :params do
default_params.merge({:access_log => value})
end

it "#{value ? "should" : "should not"} contain access logs" do
lines = subject.resource('file', "#{params[:priority]}-#{title}.conf").send(:parameters)[:content].split("\n")
!!lines.grep('_access.log combined').should == value
end
end
end
end
end
30 changes: 22 additions & 8 deletions spec/defines/vhost_spec.rb
Expand Up @@ -29,14 +29,15 @@
end

[{
:apache_name => 'httpd',
:docroot => 'path/to/docroot',
:override => ['Options', 'FileInfo'],
:port => '80',
:priority => '25',
:serveradmin => 'serveradmin@puppet',
:ssl => false,
:template => 'apache/vhost-default.conf.erb',
:apache_name => 'httpd',
:docroot => 'path/to/docroot',
:override => ['Options', 'FileInfo'],
:port => '80',
:priority => '25',
:serveradmin => 'serveradmin@puppet',
:ssl => false,
:access_log => false,
:template => 'apache/vhost-default.conf.erb',
},
].each do |param_set|

Expand Down Expand Up @@ -80,5 +81,18 @@

end
end

[true,false].each do |value|
describe "when access_log is #{value}" do
let :params do
default_params.merge({:access_log => value})
end

it "#{value ? "should" : "should not"} contain access logs" do
lines = subject.resource('file', "#{params[:priority]}-#{title}.conf").send(:parameters)[:content].split("\n")
!!lines.grep('_access.log combined').should == value
end
end
end
end
end
2 changes: 2 additions & 0 deletions templates/vhost-default.conf.erb
Expand Up @@ -23,7 +23,9 @@ NameVirtualHost <%= vhost_name %>:<%= port %>
</Directory>
ErrorLog <%= logroot %>/<%= name %>_error.log
LogLevel warn
<% if access_log -%>
CustomLog <%= logroot %>/<%= name %>_access.log combined
<% end -%>
ServerSignature Off
</VirtualHost>

2 changes: 2 additions & 0 deletions templates/vhost-proxy.conf.erb
Expand Up @@ -26,6 +26,8 @@ NameVirtualHost <%= vhost_name %>:<%= port %>

ErrorLog /var/log/<%= scope.lookupvar("apache::params::apache_name") %>/<%= name %>_error.log
LogLevel warn
<% if access_log -%>
CustomLog /var/log/<%= scope.lookupvar("apache::params::apache_name") %>/<%= name %>_access.log combined
<% end -%>
</VirtualHost>

0 comments on commit 4ffb572

Please sign in to comment.