                   (fn [s]
                     (when s (system/stop s)))))
 
-(defn reset []
-  ;; Stop the system integration test system
-  (sit-sys/stop)
-  ; Stops the running code
-  (stop)
-  ; Refreshes all of the code and then restarts the system
-  (refresh :after 'user/start))
+(defn reset
+  "Resets the development environment, reloading any changed namespaces and
+  restarting the CMR services.
 
+  Note that when an explicit mode is passed as an argument, not only will CMR
+  be restarted in that mode, but the namespace-level `user/mode` variable will
+  be reset to the given value."
+  ([]
+    (reset mode))
+  ([new-mode]
+    ;; Stop the system integration test system
+    (sit-sys/stop)
+    ; Stops the running code
+    (stop)
+    ; Refreshes all of the code and then restarts the system
+    (set-mode! new-mode)
+    (refresh :after 'user/start)))
 
 (defn run-all-tests-future
   "Runs all tests asynchronously, with :fail-fast? and :speak? enabled."

                    (constantly
                      (system/start s))))

  (d/touch-user-clj))

(defn stop
  "Shuts down and destroys the current development system."

  (config/set-config-value! :echo-rest-port 3012)
  (config/set-config-value! :echo-rest-context "/legacy-services/rest")
  (config/set-config-value! :dev-system-db-type :in-memory)
  ;; Hard coded here and here:
  ;; * legacy-services/echo/echo-env/support/db/bootstrap/business/system_acls_changeLog.xml
  ;; so that ACLs that are bootstrapped in kernel reference same Administrators group in
  ;; bootstrapped CMR.
  (transmit-config/set-administrators-group-legacy-guid! "316520E041894014E050007F010038C4"))

(defn start
  "Starts the current development system, taking the following optional
  keyword arguments, where `VALUE` is any alowed run mode:

  * `:elastic VALUE`
  * `:echo VALUE`
  * `:db VALUE`
  * `:messaging VALUE`

  If a run mode for a particular component is not passed, its value is set to
  the global run mode. If no mode has been set, the ns-level `mode` variable
  will be set to `:in-memory`.

  Note that when an explicit mode is passed as an argument, not only will CMR
  be started in that mode, but the ns-level `user/mode` variable will be reset
  to the given value."
  [& {:keys [elastic echo db messaging]
       :or {elastic mode} {echo mode} {db mode} {messaging mode}}]
  (set-mode! new-mode)
  (config/reset-config-values)

  (jobs/set-default-job-start-delay! (* 3 3600))

  (system/set-gorilla-repl-port! 8090)

  (system/set-dev-system-elastic-type! elastic)
  ;; NOTE: External ECHO does not work with the automated tests. The automated
  ;; tests expect they can interact with the Mock ECHO to setup users, acls,
  ;; and other ECHO objects.
  (system/set-dev-system-echo-type! echo)
  ;; IMPORTANT: MAKE SURE YOU DISABLE SYMANTEC ANTIVIRUS BEFORE STARTING THE
  ;; TESTS WITH EXTERNAL DB (renable them when you're done)
  (system/set-dev-system-db-type! db)
  (if aws?
    (system/set-dev-system-message-queue-type! :aws)
    (system/set-dev-system-message-queue-type! messaging))

  (sit-sys/set-logging-level @settings/logging-level)

  ;; If you would like to run CMR with legacy support, then be sure to call
  ;; `(use-legacy true)` in the REPL. There is currently no lein profile or
  ;; command line option for this.
  (when legacy?
    (configure-for-legacy-services))

  (let [s (-> (system/create-system)
              (configure-systems-logging @settings/logging-level)
