From bb64ddec92e12c80a38b22d57167972d2b68b2ac Mon Sep 17 00:00:00 2001 From: Evan Kaufman Date: Mon, 1 Feb 2016 15:03:42 -0800 Subject: [PATCH] Ensure apache logs are rotated on size threshold, and logrotate is run hourly rather than daily This resolves issues where an influx of traffic can generate significant apache logs faster than they can be rotated, resulting in potential full disk issues --- .../roles/common/files/logrotate-apache | 18 ++++++++++++++++++ provisioning/roles/common/tasks/main.yml | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 provisioning/roles/common/files/logrotate-apache diff --git a/provisioning/roles/common/files/logrotate-apache b/provisioning/roles/common/files/logrotate-apache new file mode 100644 index 0000000..c97fbed --- /dev/null +++ b/provisioning/roles/common/files/logrotate-apache @@ -0,0 +1,18 @@ +/var/log/apache2/*.log { + size 100M + missingok + rotate 10 + compress + delaycompress + notifempty + create 640 root adm + sharedscripts + postrotate + /etc/init.d/apache2 reload > /dev/null + endscript + prerotate + if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ + run-parts /etc/logrotate.d/httpd-prerotate; \ + fi; \ + endscript +} diff --git a/provisioning/roles/common/tasks/main.yml b/provisioning/roles/common/tasks/main.yml index 7f46442..5cbbcce 100644 --- a/provisioning/roles/common/tasks/main.yml +++ b/provisioning/roles/common/tasks/main.yml @@ -43,6 +43,17 @@ with_items: lamp_packages sudo: yes +- name: Configure apache log rotation + copy: src=logrotate-apache dest=/etc/logrotate.d/apache2 owner=root group=root mode=644 + sudo: yes + +- name: Ensure logrotate runs hourly + command: mv /etc/cron.daily/logrotate /etc/cron.hourly/logrotate + args: + creates: /etc/cron.hourly/logrotate + removes: /etc/cron.daily/logrotate + sudo: yes + - name: Install PHP packages apt: pkg={{item}} with_items: php_packages