diff --git a/.env.example b/.env.example index 2b49c9d..4e5c49d 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/ckan/docker-entrypoint.d/01_setup_ckanext_config.sh b/ckan/docker-entrypoint.d/01_setup_ckanext_config.sh index 9d986e9..ec95814 100644 --- a/ckan/docker-entrypoint.d/01_setup_ckanext_config.sh +++ b/ckan/docker-entrypoint.d/01_setup_ckanext_config.sh @@ -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 \ diff --git a/ckan/setup/start_ckan.sh.override b/ckan/setup/start_ckan.sh.override index bf50b4d..91cfeb4 100644 --- a/ckan/setup/start_ckan.sh.override +++ b/ckan/setup/start_ckan.sh.override @@ -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