From 6b32b29fac7bb90910f43c8f8db42d1fd37b7155 Mon Sep 17 00:00:00 2001 From: Mark Calvert Date: Wed, 7 Feb 2024 15:27:16 +1300 Subject: [PATCH] Add logrotate for CKAN app & Nginx logs --- ckan/Dockerfile.worker | 5 +++++ ckan/setup/dbca_ckan_cron_jobs | 2 ++ ckan/setup/dbca_ckan_rotate_logs | 9 +++++++++ nginx/Dockerfile | 8 ++++++++ nginx/setup/dbca_nginx_cron_jobs | 3 +++ nginx/setup/dbca_nginx_rotate_logs | 9 +++++++++ 6 files changed, 36 insertions(+) create mode 100644 ckan/setup/dbca_ckan_rotate_logs create mode 100644 nginx/setup/dbca_nginx_cron_jobs create mode 100644 nginx/setup/dbca_nginx_rotate_logs diff --git a/ckan/Dockerfile.worker b/ckan/Dockerfile.worker index 03853739..0e57d586 100644 --- a/ckan/Dockerfile.worker +++ b/ckan/Dockerfile.worker @@ -1,6 +1,11 @@ ARG CKAN_IMAGE FROM ${CKAN_IMAGE} +# Install logrotate +RUN apk add logrotate +# Create logrotate config file for app logs +COPY setup/dbca_ckan_rotate_logs /etc/logrotate.d/dbca_ckan_rotate_logs + ## Supervisor config COPY supervisor/*.conf /etc/supervisord.d diff --git a/ckan/setup/dbca_ckan_cron_jobs b/ckan/setup/dbca_ckan_cron_jobs index 618ccd81..cc3ea815 100644 --- a/ckan/setup/dbca_ckan_cron_jobs +++ b/ckan/setup/dbca_ckan_cron_jobs @@ -1,4 +1,6 @@ # Crontab for CKAN cron jobs +# Midnight task to rotate CKAN app logs every day +0 0 * * * /usr/sbin/logrotate -s /srv/app/logs/logrotate.status /etc/logrotate.d/dbca_ckan_rotate_logs # Example cron job runs the harvester run command every 15 mins #*/15 * * * * /usr/bin/ckan -c /srv/app/config/dbca.ini harvester run # Midnight task to schedule embargo datasets to public visibility diff --git a/ckan/setup/dbca_ckan_rotate_logs b/ckan/setup/dbca_ckan_rotate_logs new file mode 100644 index 00000000..71161c14 --- /dev/null +++ b/ckan/setup/dbca_ckan_rotate_logs @@ -0,0 +1,9 @@ +/srv/app/logs/ckan-worker.log /srv/app/logs/ckan-crons-jobs.log { + daily + rotate 7 + missingok + notifempty + compress + delaycompress + copytruncate +} \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 8e6bbce5..aed247e3 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -13,6 +13,13 @@ COPY setup/default.conf.template ${NGINX_DIR}/templates/ RUN mkdir -p ${NGINX_DIR}/certs +# Install logrotate +RUN apk add logrotate +# Create logrotate config file for nginx logs +COPY setup/dbca_nginx_rotate_logs /etc/logrotate.d/dbca_nginx_rotate_logs +## Cron jobs config +COPY setup/dbca_nginx_cron_jobs /etc/crontabs/root + ENTRYPOINT \ openssl req \ -subj '/C=DE/ST=Berlin/L=Berlin/O=None/CN=localhost' \ @@ -21,4 +28,5 @@ ENTRYPOINT \ -keyout ${NGINX_DIR}/certs/ckan-local.key \ -out ${NGINX_DIR}/certs/ckan-local.crt \ -days 365 && \ + /usr/sbin/crond && \ /docker-entrypoint.sh nginx -g 'daemon off;' diff --git a/nginx/setup/dbca_nginx_cron_jobs b/nginx/setup/dbca_nginx_cron_jobs new file mode 100644 index 00000000..31921db7 --- /dev/null +++ b/nginx/setup/dbca_nginx_cron_jobs @@ -0,0 +1,3 @@ +# Crontab for Nginx cron jobs +# Midnight task to rotate CKAN app logs every day +0 0 * * * /usr/sbin/logrotate -s /srv/app/logs/logrotate.status /etc/logrotate.d/dbca_nginx_rotate_logs diff --git a/nginx/setup/dbca_nginx_rotate_logs b/nginx/setup/dbca_nginx_rotate_logs new file mode 100644 index 00000000..73145028 --- /dev/null +++ b/nginx/setup/dbca_nginx_rotate_logs @@ -0,0 +1,9 @@ +/srv/app/logs/nginx_access.log /srv/app/logs/nginx_error.log { + daily + rotate 7 + missingok + notifempty + compress + delaycompress + copytruncate +} \ No newline at end of file