简体   繁体   English

我如何在不重新启动repl的情况下停止码头服务器

[英]How can I stop jetty server without restarting repl

Let's say I have a trivial boot-clj task that uses '[pandeiro.boot-http :refer [serve]] . 假设我有一个使用'[pandeiro.boot-http :refer [serve]]的琐碎的boot-clj任务。 If I make changes and need to restart the task it would complain that the port is already in use. 如果我进行更改并需要重新启动任务,它将抱怨该端口已在使用中。 Is there a way to kill jetty server without having to restart repl? 有没有一种方法可以杀死码头服务器而不必重新启动repl?

If you want only this many people use this pattern: 如果只希望有这么多人使用此模式:

(defonce running-server (atom nil))
(defn stop-server [] (@running-server))
(defn go []
  (reset! running-server
            (org.httpkit.server/run-server 
             ... your stuff here ...))

If this is a longer term project starting with something like the component framework solves this problem in a much more elegant way and allows for many dependent components (hence the name). 如果这是一个长期的项目,那么从类似组件框架这样的项目开始,可以以更优雅的方式解决此问题,并允许使用许多从属组件(因此得名)。 This is a good place to get started and worth reading before starting your next project. 这是一个入门好地方 ,值得在开始下一个项目之前阅读。

pandeiro.boot-http supports reloading of your handler so you don't have to restart the serve task. pandeiro.boot-http支持重新加载您的处理程序,因此您不必重新启动serve任务。 You need to configure it with :reload set to true : 您需要将:reload设置为true来配置它:

On command line: 在命令行上:

boot serve -H myapp.server/app -R wait

Or in your boot script: 或在您的启动脚本中:

(boot (serve :handler 'myapp.server/app :reload true) (wait))

For regular static files serve always returns the current version from the disk so there is no need for reloading for them. 对于常规的静态文件, serve总是从磁盘返回当前版本,因此无需为其重新加载。

If you really need to restart the task I guess you might be affected by issue in pandeiro.boot-http and might need to contact its maintainer. 如果您确实需要重新启动任务,我想您可能会受到pandeiro.boot-http 问题的影响,并且可能需要联系其维护者。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM