From 3e85f54b37e15be4424079beb64d6a320deb3e09 Mon Sep 17 00:00:00 2001 From: Bruno Pacheco Date: Thu, 19 Dec 2024 16:54:38 +0100 Subject: [PATCH] chore: improve logs of database upgrades --- ckan/setup/prerun.py | 27 +++++++++++++++++++++++---- harvest_sources.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 harvest_sources.md diff --git a/ckan/setup/prerun.py b/ckan/setup/prerun.py index b10c3523..145beed7 100644 --- a/ckan/setup/prerun.py +++ b/ckan/setup/prerun.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: AGPL-3.0-only import os +import pwd import sys import subprocess import psycopg2 @@ -25,6 +26,7 @@ def update_plugins(): + plugins = os.environ.get("CKAN__PLUGINS", "") print(("[prerun] Setting the following plugins in {}:".format(ckan_ini))) print(plugins) @@ -53,6 +55,7 @@ def check_main_db_connection(retry=None): conn_str = os.environ.get("CKAN_SQLALCHEMY_URL") if not conn_str: print("[prerun] CKAN_SQLALCHEMY_URL not defined, not checking db") + return return check_db_connection(conn_str, retry) @@ -107,18 +110,18 @@ def check_solr_connection(retry=None): def init_db(): - db_command = ["ckan", "-c", ckan_ini, "db", "init"] + db_command = ["ckan", "-c", ckan_ini, "db", "upgrade"] print("[prerun] Initializing or upgrading db - start") try: subprocess.check_output(db_command, stderr=subprocess.STDOUT) print("[prerun] Initializing or upgrading db - end") except subprocess.CalledProcessError as e: - if "OperationalError" in e.output: - print(e.output) + if "OperationalError" in str(e.output): print("[prerun] Database not ready, waiting a bit before exit...") time.sleep(5) sys.exit(1) else: + print(str(e)) print(e.output) raise e @@ -130,12 +133,13 @@ def init_db_harvest(): subprocess.check_output(db_command, stderr=subprocess.STDOUT) print("[prerun] Initializing or upgrading harvest db - end") except subprocess.CalledProcessError as e: - if "OperationalError" in e.output: + if "OperationalError" in str(e.output): print(e.output) print("[prerun] Database not ready, waiting a bit before exit...") time.sleep(5) sys.exit(1) else: + print(str(e)) print(e.output) raise e @@ -177,6 +181,21 @@ def create_sysadmin(): subprocess.call(command) print("[prerun] Made user {0} a sysadmin".format(name)) + # cleanup permissions + # We're running as root before pivoting to uwsgi and dropping privs + data_dir = "%s/storage" % os.environ["CKAN_STORAGE_PATH"] + + try: + user_name = "ckan-sys" + pwd.getpwnam(user_name) + command = ["chown", "-R", "ckan:ckan-sys", data_dir] + except KeyError: + user_name = "ckan" + command = ["chown", "-R", "ckan:ckan", data_dir] + subprocess.call(command) + + print("[prerun] Ensured storage directory is owned by {}".format(user_name)) + if __name__ == "__main__": diff --git a/harvest_sources.md b/harvest_sources.md new file mode 100644 index 00000000..5d37a603 --- /dev/null +++ b/harvest_sources.md @@ -0,0 +1,40 @@ + +https://fdp.gdi.biodata.pt +IST +FAIR +{"profile":"fairdatapoint_dcat_ap"} + + +http://195.148.23.230 +CSFI +FAIR +{"profile":"fairdatapoint_dcat_ap","rdf_format":"text/turtle"} + + +https://tryggve.tsd.usit.uio.no/GDI_Norway_test_data_catalog_rdf.ttl +University of Oslo +DCAT RDF +{"profile":"fairdatapoint_dcat_ap","rdf_format":"text/turtle"} + + +https://gdi.test.ega-archive.org/catalog/catalog.ttl +EGA +DCAT RDF +{"profile":"fairdatapoint_dcat_ap","rdf_format":"text/turtle"} + + +https://fairdata.dev.gdi.lu/api/fdp +LNDS FDP +FAIR +{ "profile":"fairdatapoint_dcat_ap" } + + +https://staging-fdp.gdi.nbis.se/ +NBIS +FAIR +{"profile":"fairdatapoint_dcat_ap"}