Skip to content

Commit

Permalink
Updated project to use log files for ckan, ckan-worker, ckan-cron-job…
Browse files Browse the repository at this point in the history
…s, nginx
  • Loading branch information
MarkCalvert committed Jan 31, 2024
1 parent b03f0d5 commit e232ce2
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 25 deletions.
6 changes: 6 additions & 0 deletions ckan/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ RUN for d in $APP_DIR/patches/*; do \

## DBCA specific configuration ##

## Create logs folder
RUN mkdir -p $APP_DIR/logs && \
touch $APP_DIR/logs/ckan.log && \
chown -R ckan:ckan $APP_DIR/logs && \
chmod -R 755 $APP_DIR/logs

# Override the default start_ckan.sh script
COPY setup/dbca_start_ckan.sh.override ${APP_DIR}/start_ckan.sh
RUN chmod +x ${APP_DIR}/start_ckan.sh
Expand Down
6 changes: 6 additions & 0 deletions ckan/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ RUN for d in $APP_DIR/patches/*; do \

## DBCA specific configuration ##

## Create logs folder
RUN mkdir -p $APP_DIR/logs && \
touch $APP_DIR/logs/ckan.log && \
chown -R ckan:ckan $APP_DIR/logs && \
chmod -R 755 $APP_DIR/logs

# Override the default dbca_start_ckan_development.sh script
COPY setup/dbca_start_ckan_development.sh.override ${APP_DIR}/start_ckan_development.sh
RUN chmod +x ${APP_DIR}/start_ckan_development.sh
Expand Down
6 changes: 0 additions & 6 deletions ckan/Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
ARG CKAN_IMAGE
FROM ${CKAN_IMAGE}

## Create logs folder
RUN mkdir -p $APP_DIR/logs && \
touch $APP_DIR/logs/ckan-cron-jobs.log && \
chown -R ckan:ckan $APP_DIR/logs && \
chmod -R 755 $APP_DIR/logs

## Supervisor config
COPY supervisor/*.conf /etc/supervisord.d

Expand Down
16 changes: 11 additions & 5 deletions ckan/config/dbca.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@ ckanext.qa.qsv_bin=/usr/local/bin/qsv
keys = root, ckan, ckanext, werkzeug

[handlers]
keys = console
keys = console, fileHandler

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
handlers = console, fileHandler

[logger_werkzeug]
level = WARNING
handlers = console
handlers = console, fileHandler
qualname = werkzeug
propagate = 0

[logger_ckan]
level = INFO
handlers = console
handlers = console, fileHandler
qualname = ckan
propagate = 0

[logger_ckanext]
level = DEBUG
handlers = console
handlers = console, fileHandler
qualname = ckanext
propagate = 0

Expand All @@ -90,5 +90,11 @@ args = (sys.stderr,)
level = NOTSET
formatter = generic

[handler_fileHandler]
class = handlers.TimedRotatingFileHandler
args = ('/srv/app/logs/ckan.log', 'midnight', 1, 0)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s
6 changes: 3 additions & 3 deletions ckan/setup/dbca_ckan_cron_jobs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Crontab for CKAN cron jobs
# Example cron job runs the harvester run command every 15 mins
#*/15 * * * * /usr/bin/ckan -c /srv/app/ckan.ini harvester run >> $APP_DIR/logs/ckan-cron-jobs.log 2>&1
#*/15 * * * * /usr/bin/ckan -c /srv/app/config/dbca.ini harvester run
# Midnight task to schedule embargo datasets to public visibility
0 0 * * * /usr/bin/ckan -c /srv/app/config/dbca/ckan.ini dbca scheduled_datasets >> $APP_DIR/logs/ckan-cron-jobs.log 2>&1
0 0 * * * /usr/bin/ckan -c /srv/app/config/dbca.ini dbca scheduled_datasets
# Midnight report generation for archiver broken links
0 0 * * * /usr/bin/ckan -c /srv/app/ckan.ini report generate >> $APP_DIR/logs/ckan-cron-jobs.log 2>&1
0 0 * * * /usr/bin/ckan -c /srv/app/config/dbca.ini report generate
8 changes: 5 additions & 3 deletions ckan/supervisor/ckan_cron_jobs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
[program:ckan-cron-jobs]

; Use the full paths to the virtualenv and your configuration file here.
command=/usr/sbin/crond -f -L /srv/app/logs/ckan-cron-jobs.log
# This configuration sets up a cron job for CKAN.
# The command exports the CKAN__PLUGINS environment variable by extracting the value from the dbca.ini file.
# It then executes the crond command with the -f flag to run in the foreground.
command=/bin/bash -c "export CKAN__PLUGINS=$(grep '^ckan\.plugins' $APP_DIR/config/dbca.ini | cut -d'=' -f2); exec /usr/sbin/crond -f"


; User the worker runs as.
Expand All @@ -23,8 +26,7 @@ process_name=%(program_name)s-%(process_num)02d


; Log files.
stdout_logfile=/srv/app/logs/ckan-crons-jobs.stdout.log
stderr_logfile=/srv/app/logs/ckan-crons-jobs.stderr.log
stderr_logfile=/srv/app/logs/ckan-crons-jobs.log


; Make sure that the worker is started on system start and automatically
Expand Down
6 changes: 4 additions & 2 deletions ckan/supervisor/ckan_worker_bulk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[program:ckan-worker-bulk]

; Use the full paths to the virtualenv and your configuration file here.
# This configuration file specifies the command to run for the CKAN worker bulk process.
# The command exports the CKAN__PLUGINS environment variable by extracting the value from the dbca.ini configuration file.
# It then executes the ckan command with the specified configuration file and runs the jobs worker bulk command.
command=/bin/bash -c "export CKAN__PLUGINS=$(grep '^ckan\.plugins' $APP_DIR/config/dbca.ini | cut -d'=' -f2); exec /usr/bin/ckan -c /srv/app/config/dbca.ini jobs worker bulk"


Expand All @@ -23,8 +26,7 @@ process_name=%(program_name)s-%(process_num)02d


; Log files.
stdout_logfile=/srv/app/logs/ckan-worker.stdout.log
stderr_logfile=/srv/app/logs/ckan-worker.stderr.log
stderr_logfile=/srv/app/logs/ckan-worker.log


; Make sure that the worker is started on system start and automatically
Expand Down
6 changes: 4 additions & 2 deletions ckan/supervisor/ckan_worker_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[program:ckan-worker-default]

; Use the full paths to the virtualenv and your configuration file here.
# This configuration file specifies the command to run for the CKAN worker bulk process.
# The command exports the CKAN__PLUGINS environment variable by extracting the value from the dbca.ini configuration file.
# It then executes the ckan command with the specified configuration file and runs the jobs worker command.
command=/bin/bash -c "export CKAN__PLUGINS=$(grep '^ckan\.plugins' $APP_DIR/config/dbca.ini | cut -d'=' -f2); exec /usr/bin/ckan -c /srv/app/config/dbca.ini jobs worker"


Expand All @@ -23,8 +26,7 @@ process_name=%(program_name)s-%(process_num)02d


; Log files.
stdout_logfile=/srv/app/logs/ckan-worker.stdout.log
stderr_logfile=/srv/app/logs/ckan-worker.stderr.log
stderr_logfile=/srv/app/logs/ckan-worker.log


; Make sure that the worker is started on system start and automatically
Expand Down
6 changes: 4 additions & 2 deletions ckan/supervisor/ckan_worker_priority.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[program:ckan-worker-priority]

; Use the full paths to the virtualenv and your configuration file here.
# This configuration file specifies the command to run for the CKAN worker bulk process.
# The command exports the CKAN__PLUGINS environment variable by extracting the value from the dbca.ini configuration file.
# It then executes the ckan command with the specified configuration file and runs the jobs worker priority command.
command=/bin/bash -c "export CKAN__PLUGINS=$(grep '^ckan\.plugins' $APP_DIR/config/dbca.ini | cut -d'=' -f2); exec /usr/bin/ckan -c /srv/app/config/dbca.ini jobs worker priority"


Expand All @@ -23,8 +26,7 @@ process_name=%(program_name)s-%(process_num)02d


; Log files.
stdout_logfile=/srv/app/logs/ckan-worker.stdout.log
stderr_logfile=/srv/app/logs/ckan-worker.stderr.log
stderr_logfile=/srv/app/logs/ckan-worker.log


; Make sure that the worker is started on system start and automatically
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ volumes:
ckan_storage:
pg_data:
solr_data:
ckan_logs:

services:

Expand Down Expand Up @@ -32,6 +33,7 @@ services:
- ckan_storage:/var/lib/ckan
- ./src:/srv/app/src_extensions
- ./ckan/config:/srv/app/config
- ckan_logs:/srv/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"]
Expand Down Expand Up @@ -62,6 +64,8 @@ services:
volumes:
- ckan_storage:/var/lib/ckan
- ./src:/srv/app/src_extensions
- ./ckan/config:/srv/app/config
- ckan_logs:/srv/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"]
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ volumes:
ckan_storage:
pg_data:
solr_data:
ckan_logs:

services:

Expand All @@ -25,6 +26,7 @@ services:
- "0.0.0.0:${NGINX_SSLPORT_HOST}:${NGINX_SSLPORT}"
volumes:
- ckan_storage:/var/lib/ckan
- ckan_logs:/srv/app/logs

ckan:
container_name: ${CKAN_CONTAINER_NAME}
Expand Down Expand Up @@ -53,6 +55,7 @@ services:
condition: service_healthy
volumes:
- ckan_storage:/var/lib/ckan
- ckan_logs:/srv/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"]
Expand Down Expand Up @@ -87,6 +90,7 @@ services:
condition: service_started
volumes:
- ckan_storage:/var/lib/ckan
- ckan_logs:/srv/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"]
Expand Down
5 changes: 4 additions & 1 deletion nginx/setup/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ server {
# ssl_session_cache dfine in stream and http
ssl_session_tickets off;

#access_log /var/log/nginx/host.access.log main;
access_log /srv/app/logs/nginx_access.log main;
access_log /var/log/nginx/access.log main;
error_log /srv/app/logs/nginx_error.log error;
error_log /var/log/nginx/errror.log error;

location / {
proxy_pass http://ckan:5000/;
Expand Down
5 changes: 4 additions & 1 deletion nginx/setup/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ server {
# ssl_session_cache dfine in stream and http
ssl_session_tickets off;

#access_log /var/log/nginx/host.access.log main;
access_log /srv/app/logs/nginx_access.log main;
access_log /var/log/nginx/access.log main;
error_log /srv/app/logs/nginx_error.log error;
error_log /var/log/nginx/errror.log error;

location / {
proxy_pass http://${CKAN_CONTAINER_NAME}:${CKAN_PORT}/;
Expand Down

0 comments on commit e232ce2

Please sign in to comment.