Skip to content

Commit

Permalink
Restart filebeat when rotating HAProxy logs
Browse files Browse the repository at this point in the history
The current contents of /etc/logrotate.d/haproxy are:

    /var/log/haproxy.log {
        daily
        rotate 5
        missingok
        notifempty
        compress
        postrotate
            /usr/lib/rsyslog/rsyslog-rotate
        endscript
    }

So most of this is translating from the existing logrotate config to
expressing that as a puppet resource. But also, I'm adding a filebeat
restart because filebeat is holding files open and filling up disks.
  • Loading branch information
daaang committed Aug 2, 2024
1 parent 05940e6 commit 9f0a231
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions manifests/profile/haproxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@
content => template('nebula/profile/haproxy/stats_frontend.cfg.erb'),
}

logrotate::rule { 'haproxy':
path => '/var/log/haproxy.log',
rotate_every => 'day',
rotate => 5,
missingok => true,
ifempty => false,
compress => true,
postrotate => ['/usr/lib/rsyslog/rsyslog-rotate', '/bin/systemctl restart filebeat'],
}

}
12 changes: 12 additions & 0 deletions spec/classes/profile/haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@
is_expected.to contain_file('/usr/local/bin/set_weights.rb')
end
end

describe 'log rotation' do
let(:rotate_logs) { contain_logrotate__rule("haproxy") }

it { is_expected.to rotate_logs.with_path("/var/log/haproxy.log") }
it { is_expected.to rotate_logs.with_rotate_every("day") }
it { is_expected.to rotate_logs.with_rotate(5) }
it { is_expected.to rotate_logs.with_missingok(true) }
it { is_expected.to rotate_logs.with_ifempty(false) }
it { is_expected.to rotate_logs.with_compress(true) }
it { is_expected.to rotate_logs.with_postrotate(["/usr/lib/rsyslog/rsyslog-rotate", "/bin/systemctl restart filebeat"]) }
end
end
end
end

0 comments on commit 9f0a231

Please sign in to comment.