Add logrotate meta configuration for MAAS

	- parametrize interval and rotate

Related: PROD-29848

Change-Id: Ic973ef6a1aa41ea1c3cc3e77e5353913cd7087c9
diff --git a/maas/meta/logrotate.yml b/maas/meta/logrotate.yml
new file mode 100644
index 0000000..eec9957
--- /dev/null
+++ b/maas/meta/logrotate.yml
@@ -0,0 +1,82 @@
+{%- from "maas/map.jinja" import cluster, region  with context %}
+
+{%- if cluster.get('enabled', False) %}
+  {%- set log_interval = cluster.get('logrotate', {}).get('interval', 'weekly') %}
+  {%- set log_rotation = cluster.get('logrotate', {}).get('rotate', 8) %}
+{%- elif region.get('enabled', False) %}
+  {%- set log_interval = region.get('logrotate', {}).get('interval', 'weekly') %}
+  {%- set log_rotation = region.get('logrotate', {}).get('rotate', 8) %}
+{%- endif %}
+
+{%- if cluster.get('enabled', False) or region.get('enabled', False) %}
+job:
+  maas-common:
+    - files:
+        - /var/log/maas/maas.log
+      options:
+        - {{ log_interval }}
+        - rotate: {{ log_rotation }}
+        - missingok
+        - compress
+        - delaycompress
+        - notifempty
+        # Don't rotate unless the log is at least 10MB.
+        - minsize: 10M
+        # Force rotation if the log grows beyond 50MB.
+        - maxsize: 50M
+  maas-proxy:
+    - files:
+        - /var/log/maas/proxy/*.log
+      options:
+        - {{ log_interval }}
+        - rotate: {{ log_rotation }}
+        - compress
+        - delaycompress
+        - missingok
+        - nocreate
+        - sharedscripts
+        - postrotate:
+                if [ -x /usr/sbin/squid ]; then SQUID=/usr/sbin/squid; elif  [ -x /usr/sbin/squid3 ]; then SQUID=/usr/sbin/squid3; else echo "No squid binary found" && exit 1; fi; test ! -e /var/run/maas-proxy.pid || $SQUID -f /var/lib/maas/maas-proxy.conf -k rotate
+{%- if pillar.postgresql is not defined %} ## If postgresql pillar is defined, it should be configured in postgresql pillar and not maas pillar
+  postgresql-common: # MAAS install PSQL package as a dependency thus configure PSQL log as well
+    - files:
+        - /var/log/postgresql/*.log
+      options:
+        - {{ log_interval }}
+        - rotate: {{ log_rotation }}
+        - missingok
+        - compress
+        - delaycompress
+        - copytruncate
+        - notifempty
+        - su root root
+{%- endif %}
+{%- endif %}
+{%- if cluster.get('enabled', False) %}
+  maas-rack-controller:
+    - files:
+        - /var/log/maas/rackd.log
+      options:
+        - {{ cluster.get('logrotate', {}).get('interval', 'weekly') }}
+        - rotate: {{ cluster.get('logrotate', {}).get('rotate', 8) }}
+        - compress
+        - missingok
+        - copytruncate
+        - su maas maas
+        - minsize: 10M
+        - maxsize: 50M
+{%- endif %}
+{%- if region.get('enabled', False) %}
+  maas-region-api:
+    - files:
+        - /var/log/maas/regiond.log
+      options:
+        - {{ cluster.get('logrotate', {}).get('interval', 'weekly') }}
+        - rotate: {{ cluster.get('logrotate', {}).get('rotate', 8) }}
+        - compress
+        - missingok
+        - copytruncate
+        - su maas maas
+        - minsize: 10M
+        - maxsize: 50M
+{%- endif %}
\ No newline at end of file