Skip to content

Commit

Permalink
Add logrotate for CKAN app & Nginx logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCalvert committed Feb 7, 2024
1 parent afff78a commit 6b32b29
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ckan/Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions ckan/setup/dbca_ckan_cron_jobs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions ckan/setup/dbca_ckan_rotate_logs
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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;'
3 changes: 3 additions & 0 deletions nginx/setup/dbca_nginx_cron_jobs
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions nginx/setup/dbca_nginx_rotate_logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/srv/app/logs/nginx_access.log /srv/app/logs/nginx_error.log {
daily
rotate 7
missingok
notifempty
compress
delaycompress
copytruncate
}

0 comments on commit 6b32b29

Please sign in to comment.