Replace crond with debian-based cron in CKAN startup script for background execution and improve SMTP options

- Prevent duplicate entries in crontab for harvester background processes.
This commit is contained in:
mjanez 2024-09-23 19:12:27 +00:00 committed by GitHub
parent 3fdab45448
commit 4578814d50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 4 deletions

View File

@ -115,6 +115,8 @@ CKAN_SYSADMIN_PASSWORD=test1234
CKAN_SYSADMIN_EMAIL=your_email@example.com
CKAN_STORAGE_PATH=/var/lib/ckan
CKAN_LOGS_PATH=/var/log
# SMTP settings
CKAN__SMTP_ENABLED=False
CKAN_SMTP_SERVER=smtp.corporateict.domain:25
CKAN_SMTP_STARTTLS=True
CKAN_SMTP_USER=user

View File

@ -10,6 +10,20 @@ ckan config-tool $CKAN_INI \
"search.facets.default=$SEARCH__FACETS__DEFAULT" \
"ckan.datastore.sqlsearch.enabled=$CKAN__DATASTORE__SQLSEARCH__ENABLED"
# Add SMTP settings if CKAN__SMTP_ENABLED is True
if [ "$CKAN__SMTP_ENABLED" = "True" ]; then
echo "[docker-entrypoint.01_setup_ckanext_config] Adding SMTP settings to the CKAN config file"
ckan config-tool $CKAN_INI \
"smtp.server=$CKAN_SMTP_SERVER" \
"smtp.starttls=$CKAN_SMTP_STARTTLS" \
"smtp.user=$CKAN_SMTP_USER" \
"smtp.password=$CKAN_SMTP_PASSWORD" \
"smtp.mail_from=$CKAN_SMTP_MAIL_FROM" \
"smtp.reply_to=" \
"email_to=" \
"error_email_from="
fi
# ckanext-schemingdcat: Update settings
echo "[docker-entrypoint.01_setup_ckanext_config] Loading ckanext-scheming and ckanext-schemingdcat settings into ckan.ini"
ckan config-tool $CKAN_INI \

View File

@ -24,6 +24,12 @@ if [ -n "$CKAN___LICENSES_GROUP_URL" ]; then
echo "Update licenses in CKAN"
fi
# Comment out smtp.* settings if CKAN__SMTP_ENABLED is not True
if [ "$CKAN__SMTP_ENABLED" != "True" ]; then
echo "Commenting out smtp.* settings in ini file"
sed -i 's/^\(smtp\..*\)$/#\1/' $CKAN_INI
fi
# Run the prerun script to init CKAN and create the default admin user
python3 prerun.py
@ -70,14 +76,27 @@ then
supervisord --configuration /etc/supervisord.conf &
# Workers
## Add harvester background procces to crontab
## Add the harvester background processes to crontab if they do not already exist
echo "[prerun.workers] Add harvester background procceses to crontab"
crontab -l | { cat; echo "*/15 * * * * /usr/bin/supervisorctl start ckan_harvester_run"; } | crontab -
if ! crontab -l | grep -q "/usr/bin/supervisorctl start ckan_harvester_run"; then
{ crontab -l; echo "*/15 * * * * /usr/bin/supervisorctl start ckan_harvester_run"; } | crontab -
fi
## Clean-up mechanism for the harvest log table. 'ckan.harvest.log_timeframe'. The default time frame is 30 days
crontab -l | { cat; echo "0 5 */30 * * /usr/bin/supervisorctl start ckan_harvester_clean_log"; } | crontab -
if ! crontab -l | grep -q "/usr/bin/supervisorctl start ckan_harvester_clean_log"; then
{ crontab -l; echo "0 5 */30 * * /usr/bin/supervisorctl start ckan_harvester_clean_log"; } | crontab -
fi
## Add SMTP notification process to crontab if CKAN__SMTP_ENABLED is True
if [ "$CKAN__SMTP_ENABLED" = "True" ]; then
echo "[prerun.workers] Add SMTP notification process to crontab"
if ! crontab -l | grep -q "ckan -c $CKAN_INI notify send_emails"; then
{ crontab -l; echo "@hourly echo '{}' | ckan -c $CKAN_INI notify send_emails > /dev/null"; } | crontab -
fi
fi
## Execute cron in the background
echo "[prerun.workers] Execute cron in the background"
crond -b -l 8
cron -f &
# Start uwsgi
uwsgi $UWSGI_OPTS