Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Access log flag #129

Merged
merged 5 commits into from

2 participants

@hunner
Owner

Adds an access_log parameter to enable/disable *_access.log files for apache::vhost and apache::vhost::proxy defined resources.

Closes #103

@hunner hunner merged commit 4ffb572 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2012
  1. @lboynton @hunner

    Add parameter to allow access logs to be turned off

    lboynton authored hunner committed
  2. @hunner
  3. @hunner
  4. @hunner

    Add access_log parameter to apache::vhost::proxy also

    hunner authored
    The vhosts should really be condensed into one template with multiple
    options and/or subclasses, but until that happens we just have to repeat
    code and tests.
  5. @hunner
This page is out of date. Refresh to see the latest.
View
14 manifests/vhost.pp
@@ -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",
View
14 manifests/vhost/proxy.pp
@@ -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),
View
16 spec/defines/vhost/proxy_spec.rb
@@ -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
View
30 spec/defines/vhost_spec.rb
@@ -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
View
2  templates/vhost-default.conf.erb
@@ -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>
View
2  templates/vhost-proxy.conf.erb
@@ -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>
Something went wrong with that request. Please try again.