From 1cfba750272c54d8657018df5c76d9406d0dd068 Mon Sep 17 00:00:00 2001 From: Marko Bocevski Date: Thu, 22 Oct 2020 18:11:23 +0200 Subject: [PATCH] Add setup for maintenance mode for CKAN --- compose/.ckan-env | 3 +++ compose/solr/solrconfig-2.7.9.xml | 1 + ...rconfig-2.8.5.xml => solrconfig-2.8.6.xml} | 0 ...rconfig-2.9.0.xml => solrconfig-2.9.1.xml} | 0 .../api/3/action/status_show/index.html | 9 ++++++++ .../ckan/2.7/setup/app/maintenance/index.html | 9 ++++++++ .../ckan/2.7/setup/app/maintenance/serve.py | 22 +++++++++++++++++++ images/ckan/2.7/setup/app/start_ckan.sh | 3 +++ .../api/3/action/status_show/index.html | 9 ++++++++ .../ckan/2.8/setup/app/maintenance/index.html | 9 ++++++++ .../ckan/2.8/setup/app/maintenance/serve.py | 22 +++++++++++++++++++ images/ckan/2.8/setup/app/start_ckan.sh | 3 +++ .../api/3/action/status_show/index.html | 9 ++++++++ .../ckan/2.9/setup/app/maintenance/index.html | 9 ++++++++ .../ckan/2.9/setup/app/maintenance/serve.py | 19 ++++++++++++++++ images/ckan/2.9/setup/app/start_ckan.sh | 3 +++ 16 files changed, 130 insertions(+) create mode 120000 compose/solr/solrconfig-2.7.9.xml rename compose/solr/{solrconfig-2.8.5.xml => solrconfig-2.8.6.xml} (100%) rename compose/solr/{solrconfig-2.9.0.xml => solrconfig-2.9.1.xml} (100%) create mode 100644 images/ckan/2.7/setup/app/maintenance/api/3/action/status_show/index.html create mode 100644 images/ckan/2.7/setup/app/maintenance/index.html create mode 100644 images/ckan/2.7/setup/app/maintenance/serve.py create mode 100644 images/ckan/2.8/setup/app/maintenance/api/3/action/status_show/index.html create mode 100644 images/ckan/2.8/setup/app/maintenance/index.html create mode 100644 images/ckan/2.8/setup/app/maintenance/serve.py create mode 100644 images/ckan/2.9/setup/app/maintenance/api/3/action/status_show/index.html create mode 100644 images/ckan/2.9/setup/app/maintenance/index.html create mode 100644 images/ckan/2.9/setup/app/maintenance/serve.py diff --git a/compose/.ckan-env b/compose/.ckan-env index 59e99bd..f67c88b 100644 --- a/compose/.ckan-env +++ b/compose/.ckan-env @@ -2,6 +2,9 @@ # Information about how it works: https://github.com/okfn/ckanext-envvars # Note that variables here take presedence over build/up time variables in .env +# Set to true to disable CKAN from starting and serve a maintenance page +MAINTENANCE_MODE=false + # General Settings CKAN_SITE_ID=default CKAN_SITE_URL=http://localhost:5000 diff --git a/compose/solr/solrconfig-2.7.9.xml b/compose/solr/solrconfig-2.7.9.xml new file mode 120000 index 0000000..9859b31 --- /dev/null +++ b/compose/solr/solrconfig-2.7.9.xml @@ -0,0 +1 @@ +solrconfig-2.8.6.xml \ No newline at end of file diff --git a/compose/solr/solrconfig-2.8.5.xml b/compose/solr/solrconfig-2.8.6.xml similarity index 100% rename from compose/solr/solrconfig-2.8.5.xml rename to compose/solr/solrconfig-2.8.6.xml diff --git a/compose/solr/solrconfig-2.9.0.xml b/compose/solr/solrconfig-2.9.1.xml similarity index 100% rename from compose/solr/solrconfig-2.9.0.xml rename to compose/solr/solrconfig-2.9.1.xml diff --git a/images/ckan/2.7/setup/app/maintenance/api/3/action/status_show/index.html b/images/ckan/2.7/setup/app/maintenance/api/3/action/status_show/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.7/setup/app/maintenance/api/3/action/status_show/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.7/setup/app/maintenance/index.html b/images/ckan/2.7/setup/app/maintenance/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.7/setup/app/maintenance/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.7/setup/app/maintenance/serve.py b/images/ckan/2.7/setup/app/maintenance/serve.py new file mode 100644 index 0000000..23e2dde --- /dev/null +++ b/images/ckan/2.7/setup/app/maintenance/serve.py @@ -0,0 +1,22 @@ +from SimpleHTTPServer import SimpleHTTPRequestHandler +from BaseHTTPServer import HTTPServer +from SocketServer import ThreadingMixIn +import os + +PORT = 5000 + +web_dir = os.path.join(os.path.dirname(__file__)) +os.chdir(web_dir) + +Handler = SimpleHTTPRequestHandler + + +class MaintenanceServer(ThreadingMixIn, HTTPServer): + """Handle requests in a separate thread.""" + + +if __name__ == "__main__": + httpd = MaintenanceServer(("0.0.0.0", PORT), Handler) + print("Starting maintenance mode") + httpd.serve_forever() + diff --git a/images/ckan/2.7/setup/app/start_ckan.sh b/images/ckan/2.7/setup/app/start_ckan.sh index 722783a..95b4ad5 100755 --- a/images/ckan/2.7/setup/app/start_ckan.sh +++ b/images/ckan/2.7/setup/app/start_ckan.sh @@ -18,6 +18,9 @@ UWSGI_OPTS="--socket /tmp/uwsgi.sock --uid 92 --gid 92 --http :5000 --master --e # Run the prerun script to init CKAN and create the default admin user python prerun.py +# Check if we are in maintenance mode and if yes serve the maintenance pages +if [ "$MAINTENANCE_MODE" = true ]; then PYTHONUNBUFFERED=1 python maintenance/serve.py; fi + # Run any after prerun/init scripts provided by images extending this one if [[ -d "${APP_DIR}/docker-afterinit.d" ]] then diff --git a/images/ckan/2.8/setup/app/maintenance/api/3/action/status_show/index.html b/images/ckan/2.8/setup/app/maintenance/api/3/action/status_show/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.8/setup/app/maintenance/api/3/action/status_show/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.8/setup/app/maintenance/index.html b/images/ckan/2.8/setup/app/maintenance/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.8/setup/app/maintenance/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.8/setup/app/maintenance/serve.py b/images/ckan/2.8/setup/app/maintenance/serve.py new file mode 100644 index 0000000..23e2dde --- /dev/null +++ b/images/ckan/2.8/setup/app/maintenance/serve.py @@ -0,0 +1,22 @@ +from SimpleHTTPServer import SimpleHTTPRequestHandler +from BaseHTTPServer import HTTPServer +from SocketServer import ThreadingMixIn +import os + +PORT = 5000 + +web_dir = os.path.join(os.path.dirname(__file__)) +os.chdir(web_dir) + +Handler = SimpleHTTPRequestHandler + + +class MaintenanceServer(ThreadingMixIn, HTTPServer): + """Handle requests in a separate thread.""" + + +if __name__ == "__main__": + httpd = MaintenanceServer(("0.0.0.0", PORT), Handler) + print("Starting maintenance mode") + httpd.serve_forever() + diff --git a/images/ckan/2.8/setup/app/start_ckan.sh b/images/ckan/2.8/setup/app/start_ckan.sh index 722783a..95b4ad5 100755 --- a/images/ckan/2.8/setup/app/start_ckan.sh +++ b/images/ckan/2.8/setup/app/start_ckan.sh @@ -18,6 +18,9 @@ UWSGI_OPTS="--socket /tmp/uwsgi.sock --uid 92 --gid 92 --http :5000 --master --e # Run the prerun script to init CKAN and create the default admin user python prerun.py +# Check if we are in maintenance mode and if yes serve the maintenance pages +if [ "$MAINTENANCE_MODE" = true ]; then PYTHONUNBUFFERED=1 python maintenance/serve.py; fi + # Run any after prerun/init scripts provided by images extending this one if [[ -d "${APP_DIR}/docker-afterinit.d" ]] then diff --git a/images/ckan/2.9/setup/app/maintenance/api/3/action/status_show/index.html b/images/ckan/2.9/setup/app/maintenance/api/3/action/status_show/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.9/setup/app/maintenance/api/3/action/status_show/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.9/setup/app/maintenance/index.html b/images/ckan/2.9/setup/app/maintenance/index.html new file mode 100644 index 0000000..eb43256 --- /dev/null +++ b/images/ckan/2.9/setup/app/maintenance/index.html @@ -0,0 +1,9 @@ + + + Maintenance + + +

Maintenance

+

Our data portal is currently in maintenance, please try in a while.

+ + diff --git a/images/ckan/2.9/setup/app/maintenance/serve.py b/images/ckan/2.9/setup/app/maintenance/serve.py new file mode 100644 index 0000000..fa56d40 --- /dev/null +++ b/images/ckan/2.9/setup/app/maintenance/serve.py @@ -0,0 +1,19 @@ +from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler +import os + +PORT = 5000 + +web_dir = os.path.join(os.path.dirname(__file__)) +os.chdir(web_dir) + + +def run(server_class=ThreadingHTTPServer, handler_class=SimpleHTTPRequestHandler): + server_address = ("0.0.0.0", PORT) + httpd = server_class(server_address, handler_class) + print("Starting maintenance mode") + httpd.serve_forever() + + +if __name__ == "__main__": + run() + diff --git a/images/ckan/2.9/setup/app/start_ckan.sh b/images/ckan/2.9/setup/app/start_ckan.sh index fee6687..3dc0046 100755 --- a/images/ckan/2.9/setup/app/start_ckan.sh +++ b/images/ckan/2.9/setup/app/start_ckan.sh @@ -18,6 +18,9 @@ UWSGI_OPTS="--socket /tmp/uwsgi.sock --uid ckan --gid ckan --http :5000 --master # Run the prerun script to init CKAN and create the default admin user python prerun.py +# Check if we are in maintenance mode and if yes serve the maintenance pages +if [ "$MAINTENANCE_MODE" = true ]; then PYTHONUNBUFFERED=1 python maintenance/serve.py; fi + # Run any after prerun/init scripts provided by images extending this one if [[ -d "${APP_DIR}/docker-afterinit.d" ]] then