简体   繁体   English

如何停止 clojure 中的码头服务器?

[英]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.我正在使用 ring 和 clojure 编写一个 web 应用程序。我正在为开发服务器使用 jetty 适配器,为 IDE 使用 emacs/SLIME。虽然 wrap-reload 确实有帮助,但 run-jetty 阻止了我的 slime session,我希望能够随意启动/停止它,而不必在单独的终端 session 中运行它。理想情况下,我想定义一个服务器代理和函数 start-server 和 stop-server 来启动/停止代理内部的服务器。 Is this possible?这可能吗?

I usually have a line in my Ring app that looks like the following: 我的Ring应用程序中通常有一行如下所示:

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

This prevents locking up the REPL. 这可以防止锁定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: 它还允许您在REPL中进行交互,如下所示:

user=> (.stop server)

and

user=> (.start server)

The Jetty documentation has some information on graceful shutdown of Jetty. Jetty文档提供了有关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. 我还没有开始使用compojure,但总的来说我更喜欢使用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; 除此之外,还有一个记录良好的API用于启动和关闭它,它在专用端口上侦听shutdown命令; there are ant tasks to do this, and they could of course be called from a Java app as well. 有一些ant任务可以做到这一点,当然也可以从Java应用程序中调用它们。 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. 我只是不知道Compojure将REPL连接到Web容器的运行实例,以及是否/如何自动类重新加载...希望其他人能够提供更多信息。

12 years later. 12年后。

VSCode / Calva: VS代码/卡尔瓦:

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.如果你像我一样从 VSCode / Calva 中的 repl 开始码头,你必须在终端而不是 REPL CTRL-C 服务器进程。

In fact the server process is bound to the terminal not to the REPL.事实上,服务器进程绑定到终端而不是 REPL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 clojure / ring / jetty:我正在使用> lein环形服务器。 如何配置实例化的码头实例? - clojure/ring/jetty: I am using > lein ring server. How do I configure the jetty instance that gets instantiated? 如何在Windows 7上停止Jetty服务器? - How to stop jetty server on Windows 7? 我如何在不重新启动repl的情况下停止码头服务器 - How can I stop jetty server without restarting repl 在Clojure repl中加载码头时,如何访问App Engine管理界面 - How do I access the app engine admin interface when loading jetty in the Clojure repl 我如何在 clojure 中使用环处理程序服务器静态 html 文件? - How do i server static html file with ring handler in clojure? 向Jetty服务器Clojure添加SSL支持时出错 - Error adding SSL Support to a Jetty Server Clojure Clojure:当当前变量的值与输入的值匹配时,如何使for循环停止? - Clojure: How do I have a for loop stop when the value of the current variable matches that of my input? 如何阻止 IntelliJ Cursive 重新格式化我的 Clojure 代码? - How do I stop IntelliJ Cursive from re-formating my Clojure code? 如何在Clojure中运行带有环的码头示例 - How to Run Jetty Example with Ring in Clojure 如何在Jetty中以编程方式设置gzip? - How do I programmatically set gzip in Jetty?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM