Add logrotate meta configuration for MySQL
- parametrize interval and rotate
Related: PROD-29848
Change-Id: I33d0cedbca8e2c3b02eea8ab1fcc5b0b851b0de3
diff --git a/galera/meta/logrotate.yml b/galera/meta/logrotate.yml
new file mode 100644
index 0000000..0dd91c6
--- /dev/null
+++ b/galera/meta/logrotate.yml
@@ -0,0 +1,29 @@
+## Default: Daily rotation with 28 rotations kept
+{%- from "galera/map.jinja" import master, slave with context %}
+
+{%- if master.get('enabled', False) %}
+ {%- set log_interval = master.get('logrotate', {}).get('interval', 'daily') %}
+ {%- set log_rotation = master.get('logrotate', {}).get('rotate', 28) %}
+ {%- set log_file = master.get('log_file', '/var/log/mysql.log') %}
+{%- elif slave.get('enabled', False) %}
+ {%- set log_interval = slave.get('logrotate', {}).get('interval', 'daily') %}
+ {%- set log_rotation = slave.get('logrotate', {}).get('rotate', 28) %}
+ {%- set log_file = slave.get('log_file', '/var/log/mysql.log') %}
+{%- endif %}
+
+{%- if master.get('enabled', False) or slave.get('enabled', False) %}
+job:
+ mysql-server:
+ - files:
+ - {{ log_file }}
+ - /var/log/mysql/*log
+ options:
+ - {{ log_interval }}
+ - rotate: {{ log_rotation }}
+ - missingok
+ - create 640 mysql adm
+ - compress
+ - sharedscripts
+ - postrotate:
+ test -x /usr/bin/mysqladmin || exit 0 && MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" && if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then exit 1; fi; else $MYADMIN flush-logs; fi
+{%- endif %}