             [metrics.gauges :refer [gauge-fn]]
             [metrics.timers :refer [time! timer]]
             [metrics.reporters.jmx :as jmx-reporter]
-            [murphy :refer [with-final]]
+            [murphy :refer [try! with-final]]
             [overtone.at-at :refer [mk-pool every interspaced stop-and-reset-pool!]]
             [puppetlabs.i18n.core :refer [trs tru]]
             [puppetlabs.kitchensink.core :as kitchensink]

                               get-registered-endpoints
                               (shutdown-requestor request-shutdown this)))

  (stop [this context]
        (doseq [{:keys [reporter]} (vals metrics/metrics-registries)]
          (jmx-reporter/stop reporter))
        (let [{:keys [cmd-event-mult cmd-event-ch]} context]
          (when cmd-event-mult
            (async/untap-all cmd-event-mult))
          (when cmd-event-ch
            (async/close! cmd-event-ch)))
        (stop-puppetdb context))

  (set-url-prefix [this url-prefix]
                  (let [old-url-prefix (:url-prefix (service-context this))]

  not a normal shutdown, emergency? must be set, which currently just
  produces a fatal level level log message, instead of info."
  [{:keys [stop-status] :as context}]
  (try!
   (log/info (trs "Shutdown request received; puppetdb exiting."))
   context
   (finally (some-> (:job-pool context) stop-and-reset-pool!))
   (finally
     ;; Wait up to ~5s for https://bugs.openjdk.java.net/browse/JDK-8176254
     (swap! stop-status assoc :stopping true)
     (if (utils/await-ref-state stop-status ready-to-stop? (stop-gc-wait-ms) false)
       (log/info (trs "Periodic activities halted"))
       (log/info (trs "Forcibly terminating periodic activities"))))
   (finally (close-write-dbs (get-in context [:shared-globals :scf-write-dbs])))
   (finally (some-> (get-in context [:shared-globals :scf-read-db :datasource])
                    .close))
   (finally (some-> (:command-loader context) future-cancel))
   (finally (some-> (:cmd-event-ch context) async/close!))
   (finally (some-> (:cmd-event-mult context) async/untap-all))
   (finally (stop-reporters metrics/metrics-registries))))

;; A map of required postgres settings and their expected value.
;; PuppetDB will refuse to start unless ALL of these values
