 
 (defn- stop-apps
   [system]
-  (reduce (fn [system [app {stop-fn :stop}]]
-            (update-in system [:apps app] #(when % (stop-fn %))))
+  (reduce (fn [system app]
+            (let [{stop-fn :stop} (app-control-functions app)]
+              (update-in system [:apps app] #(when % (stop-fn %)))))
           system
-          app-control-functions))
+          (reverse app-startup-order)))
 
 (defn- start-components
   [system]


(defn- start-apps
  [system]
  (reduce (fn [system [app {start-fn :start}]]
            (update-in system [:apps app]
                       #(try
                          (when %
                            (start-fn %))
                          (catch Exception e
                            (stop-components (stop-apps system))
                            (throw e)))))
          system
          app-control-functions))

(defn start
  "Performs side effects to initialize the system, acquire resources,

  "A map of application name to the start function"
  {:metadata-db {:start mdb-system/start
                 :stop mdb-system/stop}
   :index-set {:start index-set-system/start
               :stop index-set-system/stop}
   :indexer {:start indexer-system/start
