Search code examples
clojureleiningenring

How do I start many ring subprojects with a single lein task?


I have a project with three subprojects like so (using lein-sub):

(defproject trident "0.1.0"
  ...

  :sub
  ["admin"
   "api"
   "site"])

Each has a ring handler inside, something like this:

(defproject trident-api "0.1.0-SNAPSHOT"
  ...

  :ring {:handler trident.api.core/handler
         :servlet-name "trident-api"
         :init trident.api.core/init
         :port 33333})

Right now I go into each and type:

> lein ring server

This obviously gets tiresome. I also tried

> lein sub ring server

Which seems like it should work, but it only starts the first one and the process joins it! Possibly there is a way around that? It seems like this would be the simplest approach.

In lieu of that, I am now writing a leiningen task to do this for me, but am running into some issues. I can get the project file for each easily enough using leiningen.core.project/read, but from here, how do I start each ring server in a way that honors all of the dependencies and other settings from their respective project.clj files?

Any ideas?


Solution

  • I ended up building a metaserver to start all three jetty instances at once. Code is here:

    https://github.com/antler/lein-caribou/blob/master/src/leiningen/caribou/server.clj