aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Arbet <michal.arbet@ultimum.io>2021-10-07 15:45:02 +0200
committerMichal Arbet <michal.arbet@ultimum.io>2021-11-12 17:30:22 +0100
commitf229eb7e06173649974376cf689d676c673f4988 (patch)
treea588bdd3b5125850b9c417e09f99a98cba5265a6
parent7652ef325e0e84fe92ccf104bfe751a4d3542227 (diff)
downloadkolla-f229eb7e06173649974376cf689d676c673f4988.tar.gz
kolla-f229eb7e06173649974376cf689d676c673f4988.zip
Make cron's logrotate schedule configurable
Kolla-ansible allows user to change logrotate.conf, problem is that logrotate cron file is running daily by default in all distros, this is sometimes not enough. So, this patch is adding script and way how to reconfigure schedule of logrotate job (cron file). Needed-By: https://review.opendev.org/c/openstack/kolla-ansible/+/813039 Change-Id: If31b08fcf45bafc0ab25498ece9208a576aae41b
-rw-r--r--docker/cron/Dockerfile.j23
-rw-r--r--docker/cron/extend_start.sh17
2 files changed, 20 insertions, 0 deletions
diff --git a/docker/cron/Dockerfile.j2 b/docker/cron/Dockerfile.j2
index a5e65a21f..1da4d40ea 100644
--- a/docker/cron/Dockerfile.j2
+++ b/docker/cron/Dockerfile.j2
@@ -21,5 +21,8 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build
{{ macros.install_packages(cron_packages | customizable("packages")) }}
+COPY extend_start.sh /usr/local/bin/kolla_extend_start
+RUN chmod 755 /usr/local/bin/kolla_extend_start
+
{% block cron_footer %}{% endblock %}
{% block footer %}{% endblock %}
diff --git a/docker/cron/extend_start.sh b/docker/cron/extend_start.sh
new file mode 100644
index 000000000..7f78e8500
--- /dev/null
+++ b/docker/cron/extend_start.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+CRON_LOGROTATE_CURRENT_PATH="$(find /etc/cron* -name logrotate)"
+CRON_LOGROTATE_CURRENT_SCHEDULE=$(echo "${CRON_LOGROTATE_CURRENT_PATH}" | sed -r 's/(.*)(hourly|daily|weekly|monthly)(.*)/\2/g')
+
+# Pass only for hourly|daily|weekly|monthly
+if [[ "${KOLLA_LOGROTATE_SCHEDULE:-undefined}" =~ hourly|daily|weekly|monthly ]]; then
+
+ CRON_LOGROTATE_DESIRED_PATH="/etc/cron.${KOLLA_LOGROTATE_SCHEDULE}/logrotate"
+
+ if [[ "${CRON_LOGROTATE_CURRENT_PATH}" != "${CRON_LOGROTATE_DESIRED_PATH}" ]]; then
+ mv ${CRON_LOGROTATE_CURRENT_PATH} ${CRON_LOGROTATE_DESIRED_PATH}
+ CRON_LOGROTATE_CURRENT_SCHEDULE="${KOLLA_LOGROTATE_SCHEDULE}"
+ fi
+fi
+
+echo "[i] Cron schedule for logrotate is currently set to: ${CRON_LOGROTATE_CURRENT_SCHEDULE}."