<%= @matches %> {
  <%- if @user && @group -%>
  su <%= @user -%> <%= @group %>
  <%- end -%>
  daily
  missingok
  rotate <%= @days_to_keep %>
  compress
  <%- if @delaycompress -%>
  delaycompress
  <%- end -%>
  <%- if @rotate_if_empty -%>
  ifempty
  <%- else -%>
  notifempty
  <%- end -%>
  <%- if @copytruncate -%>
  copytruncate
  <%- end -%>
  <%- if @create -%>
  create <%= @create %>
  <%- end -%>
  <%- if @sharedscripts -%>
  sharedscripts
  <%- end -%>
  <%- if @prerotate -%>
  prerotate
    <%= @prerotate %>
  endscript
  <%- end -%>
  <%- if @postrotate -%>
  postrotate
    <%= @postrotate %>
  endscript
  <%- end -%>
  <%- if @maxsize -%>
  maxsize <%= @maxsize %>
  <%- end -%>
}

<%= @matches %> {
  <%- if @user && @group -%>
  su <%= @user -%> <%= @group %>
  <%- end -%>
  daily
  missingok
  rotate <%= @days_to_keep %>
  compress
  <%- if @delaycompress -%>
  delaycompress
  <%- end -%>
  <%- if @rotate_if_empty -%>
  ifempty
  <%- else -%>
  notifempty
  <%- end -%>
  <%- if @copytruncate -%>
  copytruncate
  <%- end -%>
  <%- if @create -%>
  create <%= @create %>
  <%- end -%>
  <%- if @sharedscripts -%>
  sharedscripts
  <%- end -%>
  <%- if @prerotate -%>
  prerotate
    <%= @prerotate %>
  endscript
  <%- end -%>
  <%- if @postrotate -%>
  postrotate
    <%= @postrotate %>
  endscript
  <%- end -%>
  <%- if @maxsize -%>
  maxsize <%= @maxsize %>
  <%- end -%>
  firstaction
    # Remove empty .1 log files. There seems to be an issue where logrotate
    # will refuse to rotate the logs if an empty .1 log file exists.
    find <%= @matches %>* -wholename '/var/log/*' -name '*.1' -size 0 -delete
  endscript
}

Remove empty .1 log files before rotating
Remove empty .1 log files before rotating

There seems to be a problem with logrotate whereby it will refuse
to rotate the log files if an empty .1 log file exists. This leads to
increase disk space being used by log files and can cause the disk to
fill up.

This fix should mean that all empty .1 log files are deleted before
logrotate runs which should allow it to finish successfully.
