Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #129 from hunner/access-log-flag

Access log flag
  • Loading branch information...
commit 4ffb57278d034e612d9ae6ff4e2513a9d2d8b717 2 parents dc11bfd + 799c32e
Hunter Haugen hunner authored
14 manifests/vhost.pp
View
@@ -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:
@@ -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'
) {
@@ -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",
14 manifests/vhost/proxy.pp
View
@@ -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:
@@ -27,6 +28,7 @@
$serveraliases = '',
$ssl = false,
$vhost_name = '*',
+ $access_log = true,
$no_proxy_uris = []
) {
@@ -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),
16 spec/defines/vhost/proxy_spec.rb
View
@@ -30,7 +30,8 @@
:dest => 'example2.com',
:servername => 'example3.com',
:port => '80',
- :ssl => true
+ :ssl => true,
+ :access_log => false,
},
].each do |param_set|
@@ -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 spec/defines/vhost_spec.rb
View
@@ -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|
@@ -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  templates/vhost-default.conf.erb
View
@@ -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  templates/vhost-proxy.conf.erb
View
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.