Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into issue-23
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Mar 19, 2014
2 parents 1d58f3a + d327742 commit 33d16d0
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.bundle/
vendor/gems
vendor/gems/
.ruby-version
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ missingok - A Boolean specifying whether logrotate should ignore missing
log files or issue an error (optional).
olddir - A String path to a directory that rotated logs should be
moved to (optional).
postrotate - A command String that should be executed by /bin/sh after
the log file is rotated (optional).
prerotate - A command String that should be executed by /bin/sh before
the log file is rotated and only if it will be rotated
(optional).
firstaction - A command String that should be executed by /bin/sh once
before all log files that match the wildcard pattern are
rotated (optional).
lastaction - A command String that should be execute by /bin/sh once
after all the log files that match the wildcard pattern are
rotated (optional).
postrotate - A command String or an Array of Strings that should be
executed by /bin/sh after the log file is rotated (optional).
prerotate - A command String or an Array of Strings that should be
executed by /bin/sh before the log file is rotated and only
if it will be rotated (optional).
firstaction - A command String or an Array of Strings that should be
executed by /bin/sh once before all log files that match the
wildcard pattern are rotated (optional).
lastaction - A command String or an Array of Strings that should be
executed by /bin/sh once after all the log files that match
the wildcard pattern are rotated (optional).
rotate - The Integer number of rotated log files to keep on disk
(optional).
rotate_every - How often the log files should be rotated as a String.
Expand Down
9 changes: 7 additions & 2 deletions files/etc/cron.daily/logrotate
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE
# OVERWRITTEN.

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
OUTPUT=$(/usr/sbin/logrotate /etc/logrotate.conf 2>&1)
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
echo "${OUTPUT}"
fi
exit $EXITVALUE
9 changes: 7 additions & 2 deletions files/etc/cron.hourly/logrotate
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE
# OVERWRITTEN.

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.d/hourly
OUTPUT=$(/usr/sbin/logrotate /etc/logrotate.d/hourly 2>&1)
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
echo "${OUTPUT}"
fi
exit $EXITVALUE
31 changes: 20 additions & 11 deletions manifests/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@
# log files or issue an error (optional).
# olddir - A String path to a directory that rotated logs should be
# moved to (optional).
# postrotate - A command String that should be executed by /bin/sh after
# the log file is rotated (optional).
# prerotate - A command String that should be executed by /bin/sh before
# the log file is rotated and only if it will be rotated
# (optional).
# firstaction - A command String that should be executed by /bin/sh once
# before all log files that match the wildcard pattern are
# rotated (optional).
# lastaction - A command String that should be execute by /bin/sh once
# after all the log files that match the wildcard pattern are
# rotated (optional).
# postrotate - A command String or an Array of Strings that should be
# executed by /bin/sh after the log file is rotated
# optional).
# prerotate - A command String or an Array of Strings that should be
# executed by /bin/sh before the log file is rotated and
# only if it will be rotated (optional).
# firstaction - A command String or an Array of Strings that should be
# executed by /bin/sh once before all log files that match
# the wildcard pattern are rotated (optional).
# lastaction - A command String or an Array of Strings that should be
# executed by /bin/sh once after all the log files that match
# the wildcard pattern are rotated (optional).
# rotate - The Integer number of rotated log files to keep on disk
# (optional).
# rotate_every - How often the log files should be rotated as a String.
Expand Down Expand Up @@ -406,9 +407,17 @@
'hour', 'hourly': {
include logrotate::hourly
$rule_path = "/etc/logrotate.d/hourly/${name}"

file { "/etc/logrotate.d/${name}":
ensure => absent,
}
}
default: {
$rule_path = "/etc/logrotate.d/${name}"

file { "/etc/logrotate.d/hourly/${name}":
ensure => absent,
}
}
}

Expand Down
65 changes: 65 additions & 0 deletions spec/defines/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,17 @@
end
end

context "and postrotate => ['/bin/true', '/bin/false']" do
let(:params) {
{:path => '/var/log/foo.log', :postrotate => ['/bin/true', '/bin/false']}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/postrotate\n \/bin\/true\n \/bin\/false\n endscript/)
end
end

###########################################################################
# PREROTATE
context 'and prerotate => /bin/true' do
Expand All @@ -684,6 +695,17 @@
end
end

context "and prerotate => ['/bin/true', '/bin/false']" do
let(:params) {
{:path => '/var/log/foo.log', :prerotate => ['/bin/true', '/bin/false']}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/prerotate\n \/bin\/true\n \/bin\/false\n endscript/)
end
end

###########################################################################
# FIRSTACTION
context 'and firstaction => /bin/true' do
Expand All @@ -697,6 +719,17 @@
end
end

context "and firstaction => ['/bin/true', '/bin/false']" do
let(:params) {
{:path => '/var/log/foo.log', :firstaction => ['/bin/true', '/bin/false']}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/firstaction\n \/bin\/true\n \/bin\/false\n endscript/)
end
end

###########################################################################
# LASTACTION
context 'and lastaction => /bin/true' do
Expand All @@ -710,6 +743,17 @@
end
end

context "and lastaction => ['/bin/true', '/bin/false']" do
let(:params) {
{:path => '/var/log/foo.log', :lastaction => ['/bin/true', '/bin/false']}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/lastaction\n \/bin\/true\n \/bin\/false\n endscript/)
end
end

###########################################################################
# ROTATE
context 'and rotate => 3' do
Expand Down Expand Up @@ -744,6 +788,7 @@

it { should contain_class('logrotate::hourly') }
it { should contain_file('/etc/logrotate.d/hourly/test') }
it { should contain_file('/etc/logrotate.d/test').with_ensure('absent') }
end

context 'and rotate_every => day' do
Expand All @@ -755,6 +800,11 @@
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ daily$/)
end

it do
should contain_file('/etc/logrotate.d/hourly/test') \
.with_ensure('absent')
end
end

context 'and rotate_every => week' do
Expand All @@ -766,6 +816,11 @@
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ weekly$/)
end

it do
should contain_file('/etc/logrotate.d/hourly/test') \
.with_ensure('absent')
end
end

context 'and rotate_every => month' do
Expand All @@ -777,6 +832,11 @@
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ monthly$/)
end

it do
should contain_file('/etc/logrotate.d/hourly/test') \
.with_ensure('absent')
end
end

context 'and rotate_every => year' do
Expand All @@ -788,6 +848,11 @@
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ yearly$/)
end

it do
should contain_file('/etc/logrotate.d/hourly/test') \
.with_ensure('absent')
end
end

context 'and rotate_every => foo' do
Expand Down
20 changes: 16 additions & 4 deletions templates/etc/logrotate.d/rule.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,34 @@
<% end -%>
<% if @postrotate != 'undef' -%>
postrotate
<%= @postrotate %>
<%- @postrotate = [@postrotate] unless @postrotate.is_a?(Array) -%>
<%- @postrotate.each do |val| -%>
<%= val %>
<%- end -%>
endscript
<% end -%>
<% if @prerotate != 'undef' -%>
prerotate
<%= @prerotate %>
<%- @prerotate = [@prerotate] unless @prerotate.is_a?(Array) -%>
<%- @prerotate.each do |val| -%>
<%= val %>
<%- end -%>
endscript
<% end -%>
<% if @firstaction != 'undef' -%>
firstaction
<%= @firstaction %>
<%- @firstaction = [@firstaction] unless @firstaction.is_a?(Array) -%>
<%- @firstaction.each do |val| -%>
<%= val %>
<%- end -%>
endscript
<% end -%>
<% if @lastaction != 'undef' -%>
lastaction
<%= @lastaction %>
<%- @lastaction = [@lastaction] unless @lastaction.is_a?(Array) -%>
<%- @lastaction.each do |val| -%>
<%= val %>
<%- end -%>
endscript
<% end -%>
}

0 comments on commit 33d16d0

Please sign in to comment.