Skip to content
Snippets Groups Projects
Commit c5e97e00 authored by Tom Robinson's avatar Tom Robinson
Browse files

Change backend to start Jetty immediately, add show loading screen until db is ready

parent 7209c68f
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Metabase</title>
</head>
<body>
Initializing Metabase, please wait...
<script type="text/javascript">
setTimeout(function() {
window.location.reload();
}, 2500);
</script>
</body>
</html>
......@@ -35,7 +35,9 @@
(context "/dataset" [] (+auth dataset/routes))
(context "/field" [] (+auth field/routes))
(context "/foreignkey" [] (+auth fk/routes))
(GET "/health" [] {:status 200 :body {:status "ok"}})
(GET "/health" [] (if ((resolve 'metabase.core/initialized?))
{:status 200 :body {:status "ok"}}
{:status 503 :body {:status "initializing"}}))
(context "/notify" [] (+apikey notify/routes))
(context "/revision" [] (+auth revision/routes))
(context "/session" [] session/routes)
......
......@@ -23,6 +23,7 @@
;; check here for all available options:
;; https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj
:mb-jetty-port "3000"
:mb-jetty-join "false"
;; Other Application Settings
:mb-password-complexity "normal"
;:mb-password-length "8"
......
......@@ -71,6 +71,13 @@
;;; ## ---------------------------------------- LIFECYCLE ----------------------------------------
(def ^:private metabase-initialized
(atom false))
(defn initialized?
"Metabase is initialized and ready to be served"
[]
@metabase-initialized)
(defn- -init-create-setup-token
"Create and set a new setup token, and open the setup URL on the user's system."
......@@ -128,6 +135,7 @@
(sample-data/update-sample-dataset-if-needed!)))
(log/info "Metabase Initialization COMPLETE")
(reset! metabase-initialized true)
true)
......@@ -168,10 +176,12 @@
(defn- start-normally []
(log/info "Starting Metabase in STANDALONE mode")
(try
;; launch embedded webserver async
(start-jetty)
;; run our initialization process
(init)
;; launch embedded webserver
(start-jetty)
;; Ok, now block forever while Jetty does its thing
(.join ^org.eclipse.jetty.server.Server @jetty-instance)
(catch Exception e
(.printStackTrace e)
(log/error "Metabase Initialization FAILED: " (.getMessage e)))))
......
......@@ -9,12 +9,18 @@
[metabase.models.setting :as setting]))
(defn- index [_]
(-> (io/resource "frontend_client/index.html")
slurp
(stencil/render-string {:bootstrap_json (json/generate-string (setting/public-settings))})
resp/response
(resp/content-type "text/html")
(resp/header "Last-Modified" "{now} GMT")))
(if ((resolve 'metabase.core/initialized?))
(-> (io/resource "frontend_client/index.html")
slurp
(stencil/render-string {:bootstrap_json (json/generate-string (setting/public-settings))})
resp/response
(resp/content-type "text/html")
(resp/header "Last-Modified" "{now} GMT"))
(-> (io/resource "frontend_client/init.html")
slurp
resp/response
(resp/content-type "text/html")
(resp/header "Last-Modified" "{now} GMT"))))
;; Redirect naughty users who try to visit a page other than setup if setup is not yet complete
(defroutes routes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment