From 4d4830c144e370fe5f1c043d4061a5698ea6ee4f Mon Sep 17 00:00:00 2001
From: "egon w. stemle" <egon.stemle@eurac.edu>
Date: Thu, 27 Jun 2019 10:44:55 +0200
Subject: [PATCH] Add cronjob as subshell (and ensure single run)

Instead of an external CronJob pod, or a supervisord cron daemon, we use
a subshell. Also we assume, the regular cronjob *also* needs to run when
the container starts. Insofar, we start the subshell, make sure it runs
a single time (and continues in the background) and then continue with
starting clarin-dspace.

Address #48
---
 .../commul-customization/entrypoint.sh        | 30 ++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/dockerfiles/commul-customization/entrypoint.sh b/dockerfiles/commul-customization/entrypoint.sh
index c7890a4..469fa87 100644
--- a/dockerfiles/commul-customization/entrypoint.sh
+++ b/dockerfiles/commul-customization/entrypoint.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # replace environment variables in config files
 perl -pi -e 's/\$\{DSPACE_USER\}/$ENV{DSPACE_USER}/; s/\$\{DSPACE_PASSWORD\}/$ENV{DSPACE_PASSWORD}/; s/\$\{MAIL_USER\}/$ENV{MAIL_USER}/; s/\$\{MAIL_PASSWORD\}/$ENV{MAIL_PASSWORD}/; s/\$\{DSPACE_DBNAME\}/$ENV{DSPACE_DBNAME}/; s/\$\{DSPACE_UTILSDBNAME\}/$ENV{DSPACE_UTILSDBNAME}/;' /opt/repository/sources/dspace/local.properties
@@ -16,9 +16,31 @@ perl -pi -e 's/\$\{HANDLE_USER\}/$ENV{HANDLE_USER}/; s/\$\{HANDLE_PASSWORD\}/$EN
 /opt/tomcat8/bin/startup.sh
 cd /opt/repository/workspace/scripts
 make init_statistics
-make update_discovery
-make update_oai
-/opt/lindat-dspace/installation/bin/dspace generate-sitemaps
+
+# https://ubuntuforums.org/showthread.php?t=979694
+# Start process in the background and send its output to file descriptor 3
+exec 3< <(while (true); do
+    make update_oai
+    make update_statistics
+    make update_sitemap
+    make lift_embargos
+    make update_openaire_cache
+    make update_discovery
+    echo "INIT DONE."
+    sleep 86400
+done)
+
+# Read the output of the process line by line until one line contains Ready
+while read line; do
+   case "$line" in
+   "INIT DONE.")
+      break
+      ;;
+   esac
+done <&3
+
+# Close the file descriptor
+exec <&3 3<&-
 /opt/tomcat8/bin/shutdown.sh -force
 
 # start tomcat
-- 
GitLab