<%
to_rotate_hourly = @service_port_map.keys
unless to_rotate_hourly.empty?
%>
<%=
to_rotate_hourly.map { |name| "#{ @log_dir }/cdn-#{ name }.log" }.join("\n")
-%>

{
  su root deploy
  rotate 3
  dateext
  dateformat -%Y%m%d-%s
  compress
  size 1
  missingok
  postrotate
    invoke-rc.d rsyslog reload >/dev/null 2>&1 || true
    sleep 10
  endscript
}
<% end %>

<%
to_rotate_hourly = @service_port_map.keys
unless to_rotate_hourly.empty?
%>
<%=
to_rotate_hourly.map { |name| "#{ @log_dir }/cdn-#{ name }.log" }.join("\n")
-%>

{
  su root deploy
  rotate 3
  dateext
  dateformat -%Y%m%d-%s
  compress
  size 1
  copytruncate
  missingok
}
<% end %>

Use copytruncate to rotate CDN logs
Use copytruncate to rotate CDN logs

cf9fd75 moved CDN logs from the `logs-cdn` machine class to
`monitoring`, and also changed the frequency of log rotation from
daily to hourly.

On staging, traffic on the govuk CDN is so slow that frequently an
hour passes with no traffic.  In consequence, the logs are frequently
rotated between checks.  This causes a critical alert as the expected
log file does not exist.

The `copytruncate` option in logrotate causes it to leave the original
file in place, but truncate it.  This solves the alert problem.  As
it's the original file, we don't need to reload rsyslog, as its
current file handles will still be valid.
