Skip to content

Commit ffc5960

Browse files
author
Stig Sandbeck Mathisen
committed
Initial import of logrotate::conf definition for log rotation
1 parent de46937 commit ffc5960

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

logrotate/README

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
A custom definition for log rotation with logrotate:
2+
3+
Parameters:
4+
logfiles
5+
interval: "daily", "weekly" or "monthly". Default: "daily"
6+
dateext: true or false, default: true
7+
compress: true or false: default: true
8+
delaycompress: true or false, default: true
9+
sharedscripts: true or false, default: true
10+
rotate: a postitive integer, default:7
11+
postrotate: false, or a string refering to a command to run: default: false
12+
customlines: an array containing any other configuration lines for logrotate, or comments
13+
14+
Example:
15+
16+
# logrotate::conf { "foo":
17+
# logfiles => "/var/log/foo.log",
18+
# postrotate => "/etc/init.d/foo reload",
19+
# sharedscripts => false,
20+
#
21+
# customlines => ["# foo", "# bar"]
22+
# }

logrotate/manifests/conf.pp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Example:
2+
# (creates /etc/logrotate.d/foo.conf)
3+
# logrotate::conf { "foo":
4+
# logfiles => ["/var/log/foo.log", "/var/log/foo-debug.log", "/var/log/foo/*.log"],
5+
# interval => "daily",
6+
# dateext => true,
7+
# rotate => 5,
8+
# compress => true,
9+
# delaycompress => true,
10+
# sharedscripts => true,
11+
# postrotate => "/etc/init.d/foo reload";
12+
# }
13+
define logrotate::conf ($logfiles, $interval="daily", $dateext=true, $compress=true, $delaycompress=true, $sharedscripts=true, $rotate=7, $postrotate=false, $customlines=[]) {
14+
15+
case $interval {
16+
"daily",
17+
"weekly",
18+
"monthly": {}
19+
default: { fail("Unknown interval: $interval")}
20+
}
21+
22+
file {"/etc/logrotate.d/$name":
23+
content => template("logrotate/logrotate.erb")
24+
}
25+
}
26+

logrotate/templates/logrotate.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Logrotate script for <%= name %>
2+
<%= logfiles %>
3+
<%= interval %>
4+
rotate <%= rotate %>
5+
<%= compress ? "compress" : "" %>
6+
<%= delaycompress ? "delaycompress" : "" %>
7+
<%= sharedscripts ? "sharedscripts" : "" %>
8+
9+
<% unless postrotate == false -%>
10+
postrotate
11+
<%= postrotate %>
12+
endscript
13+
<% end -%>
14+
15+
<% customlines.flatten.each do |line| -%>
16+
<%= line %>
17+
<% end -%>

0 commit comments

Comments
 (0)