Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop jetty server in clojure?

I am writing a web application using ring and clojure. I am using the jetty adapter for the development server and emacs/SLIME for IDE. While wrap-reload does help, run-jetty blocks my slime session and I would like to be able to start/stop it at will without having to run it in a separate terminal session. Ideally, I would like to define a server agent and functions start-server and stop-server that would start/stop the server inside the agent. Is this possible?

like image 657
Mad Wombat Avatar asked Apr 24 '10 20:04

Mad Wombat


People also ask

How do I shutdown a jetty server?

If jetty as maven plugin, you stop the server by pressing Ctrl + C and press Y to confirm terminate.

How do I access my jetty server?

Identify the IP-number of the computer running Jetty (not 127.0. 0.1) and see if you can connect to "http://that-ip-number:8080" from the machine itself. If this doesn't work, fix your jetty configuration. Then put another computer on the same network and connect to "http://that-ip-number:8080" too.


3 Answers

I usually have a line in my Ring app that looks like the following:

(defonce server (run-jetty #'my-app {:port 8080 :join? false})) 

This prevents locking up the REPL. It also allows me to recompile this file without worrying that my server will get redefined. It also lets you interact at the REPL like so:

user=> (.stop server) 

and

user=> (.start server) 
like image 179
dnolen Avatar answered Sep 30 '22 06:09

dnolen


The Jetty documentation has some information on graceful shutdown of Jetty. That's probably not enough information but it may get you started.

I haven't started playing with compojure yet, but overall I prefer to work with Tomcat. It's more full-featured; among other things, there is a well-documented API for starting it up and shutting it down, it listens for the shutdown command on a dedicated port; there are ant tasks to do this, and they could of course be called from a Java app as well. I just don't know what kind of magic Compojure does with connecting the REPL to a running instance of the Web container, and if/how automatic class reloading happens... hopefully someone else will be able to provide more information.

like image 40
Carl Smotricz Avatar answered Sep 30 '22 07:09

Carl Smotricz


12 years later.

VSCode / Calva:

If you are like me starting jetty from the repl inside VSCode / Calva you have to CTRL-C the server process at the terminal not the REPL.

In fact the server process is bound to the terminal not to the REPL.

like image 44
simou Avatar answered Sep 30 '22 06:09

simou