Skip to content

Instantly share code, notes, and snippets.

@tolitius
Created December 29, 2016 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolitius/51efc53e6d3643f5189756b68ca172bc to your computer and use it in GitHub Desktop.
Save tolitius/51efc53e6d3643f5189756b68ca172bc to your computer and use it in GitHub Desktop.
starting / stopping an http server

this is the snippet that manages the http server lifecycle:

(defstate web-server :start (start-www config)
                     :stop (.stop web-server))

Trying it

$ git clone https://github.com/tolitius/stater
$ cd stater/smsio

boot into REPL:

$ boot repl                                                                                                    (master ✔ )
nREPL server started on port 50164 on host 127.0.0.1 - nrepl://127.0.0.1:50164

boot.user=> (dev)
#object[clojure.lang.Namespace 0x109e474 "dev"]

starting it:

dev=> (mount/start #'app.conf/config #'app.www/web-server)

INFO  app.conf - loading config from dev/resources/config.edn
23:41:32.078 [nREPL-worker-0] DEBUG o.e.jetty.util.component.Container - Container org.eclipse.jetty.server.Server@53ec06fb + SelectChannelConnector@0.0.0.0:4242 as connector
...
23:41:32.116 [nREPL-worker-0] DEBUG o.e.j.u.component.AbstractLifeCycle - STARTED org.eclipse.jetty.server.Server@53ec06fb

{:started ["#'app.conf/config" "#'app.www/web-server"]}
dev=>

stopping it:

dev=> (mount/stop #'app.www/web-server)

23:41:37.690 [nREPL-worker-0] DEBUG o.e.j.u.component.AbstractLifeCycle - stopping org.eclipse.jetty.server.Server@53ec06fb
...
23:41:37.775 [nREPL-worker-0] DEBUG o.e.j.u.component.AbstractLifeCycle - STOPPED org.eclipse.jetty.server.Server@53ec06fb

{:stopped ["#'app.www/web-server"]}
dev=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment