Fork me on GitHub

Hey everyone! Does anyone know how to keep a lein process running after it spawned some server? I’m trying to create a simple lein plugin to just run the new nREPL server, but I hit a surprising roadblock - the server starts and then lein just exits and kills it.

(defn nrepl
  "Start a headless nREPL server within your project's context."
  [project & args]
  (println args)
   `(start-nrepl ~(convert-args args))))
(this just uses the start-nrepl wrapper from cider-nrepl and passes it a hash with the params it normally expects. I took a look at and I don’t quite understand everything it does to spin the headless server, so I decided it might be simpler to ask here.


Basically it seems to me that the magic happens here:

(defn server [project cfg headless?]
  (when-not (nrepl-dependency? project)
    (main/info "Warning: no nREPL dependency detected.")
    (main/info "Be sure to include org.clojure/tools.nrepl in :dependencies"
               "of your profile."))
  (let [prep-blocker @eval/prep-blocker
        ack-port (:port @ack-server)]
    (-> (bound-fn []
          (binding [eval/*pump-in* false]
            (let [[evals requires]
                  (server-forms project cfg ack-port headless?)]
              (eval/eval-in-project project
                                    `(do ~(ignore-sigint-form) ~evals)
        (Thread.) (.start))
    (when project @prep-blocker)
    (when headless? @(promise))
    (if-let [repl-port (nrepl.ack/wait-for-ack
                        (get-in project [:repl-options :timeout] 60000))]
      (do (main/info "nREPL server started on port"
                     repl-port "on host" (:host cfg)
                     (str "- nrepl://" (:host cfg) ":" repl-port))
      (main/abort "REPL server launch timed out."))))
But I wondered if there isn’t some general purpose machinery in Lein for dealing with daemons.


(when headless? @(promise))