                  ;; This coordination is needed until we no longer
                  ;; support jdk < 10.
                  ;; https://bugs.openjdk.java.net/browse/JDK-8176254
-                 :stop-status (atom #{}))))
+                 :stop-status (atom #{})
+                 :shutdown-request (promise))))
   (start
    [this context]
    (start-puppetdb-or-shutdown context (get-config) this
                                get-registered-endpoints
-                               shutdown-on-error))
+                               (shutdown-requestor request-shutdown
+                                                   shutdown-on-error
+                                                   this)))
 
   (stop [this context]
         (doseq [{:keys [reporter]} (vals metrics/metrics-registries)]

    (async/>!! cmd-event-ch (queue/make-cmd-event cmdref kind))))

(defn check-schema-version
  [desired-schema-version context db service shutdown-on-error]
  {:pre [(integer? desired-schema-version)]}
  (when-not (= #{:stopping} @(:stop-status context))
    (let [schema-version (-> (jdbc/with-transacted-connection db


                       :else
                       (throw (Exception. "Unknown state when checking schema versions")))]
          (request-shutdown {::tk/exit
                             {:status 1  ;; Unsuppported by older TK (will be 1)
                              :messages [[ex-msg *err*]]}}))))))

(defn start-puppetdb
  "Throws {:kind ::unsupported-database :current version :oldest version} if
  the current database is not supported. If a database setting is configured
  incorrectly, throws {:kind ::invalid-database-configuration :failed-validation failed-map}"
  [context config service get-registered-endpoints request-shutdown]
  (let [{:keys [developer jetty
                database read-database
                puppetdb command-processing
