我写了一个20分钟的网络服务,我需要快速部署,所以我想到了Heroku。我按照他们的例子,按照文档添加了一个Procfile:
web: java $JVM_OPTS -cp target/random-pairs.jar Clojure.main -m random-pairs.system
服务器只是包含在Component / Lifecycle接口实现中的jetty,所以我添加了从Heroku ENV读取PORT / HOST的调用,也没多久:
(defn new []
(let [host (or (System/getenv "HOST") "localhost")
port (or (Integer. (System/getenv "PORT")) 8080)]
(map->Server {:host host :port port :server nil :database nil})))
然后我推到了heroku分支,非常高兴看到它构建:
remote: -----> Clojure (Leiningen 2) app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Using cached Leiningen 2.7.1
remote: Writing: lein script
remote: -----> Building with Leiningen
remote: Running: lein uberjar
remote: Compiling random-pairs.api
remote: Compiling random-pairs.routing
remote: Compiling random-pairs.server
remote: Compiling random-pairs.system
remote: Compiling random-pairs.utils
remote: Created /tmp/build_39db3b5354727cb980092a4caa080664/target/random-pairs-0.1.0-SNAPSHOT.jar
remote: Created /tmp/build_39db3b5354727cb980092a4caa080664/target/random-pairs.jar
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 70.5M
remote: -----> Launching...
我偷看了原木确认:
2017-09-27T10:11:43.214499+00:00 heroku[web.1]: Starting process with command `java $JVM_OPTS -cp target/random-pairs.jar clojure.main -m random-pairs.system`
2017-09-27T10:11:46.312843+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-09-27T10:11:46.316262+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2017-09-27T10:11:49.562990+00:00 app[web.1]: 2017-09-27 10:11:49.559 INFO default org.eclipse.jetty.util.log - Logging initialized @3234ms
2017-09-27T10:11:50.401779+00:00 app[web.1]: 2017-09-27 10:11:50.401 INFO default random-pairs.system - :random-pairs.system/create-system Creating system
2017-09-27T10:11:50.404459+00:00 app[web.1]: 2017-09-27 10:11:50.404 INFO default random-pairs.system - :random-pairs.system/start Starting the application
2017-09-27T10:11:50.409370+00:00 app[web.1]: 2017-09-27 10:11:50.409 INFO default random-pairs.server - :random-pairs.server/server-start Starting Server component host: localhost port: 15701
2017-09-27T10:11:50.435805+00:00 app[web.1]: 2017-09-27 10:11:50.435 INFO default org.eclipse.jetty.server.Server - jetty-9.2.z-SNAPSHOT
2017-09-27T10:11:50.478304+00:00 app[web.1]: 2017-09-27 10:11:50.477 INFO default o.e.jetty.server.ServerConnector - Started ServerConnector@1a1f79ce{HTTP/1.1}{localhost:15701}
2017-09-27T10:11:50.478742+00:00 app[web.1]: 2017-09-27 10:11:50.478 INFO default org.eclipse.jetty.server.Server - Started @4162ms
2017-09-27T10:11:50.479247+00:00 app[web.1]: 2017-09-27 10:11:50.479 INFO default random-pairs.system - :random-pairs.system/main Application fully functional
很好,Heroku看起来很整洁。 所以我继续发送一些请求测试一切正常。只是它没有。我再次看了看日志只看到:
2017-09-27T10:13:48.345516+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-09-27T10:13:48.345575+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-09-27T10:13:48.488069+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-27T10:13:48.476415+00:00 heroku[web.1]: Process exited with status 137
宙斯的名字是什么?无法绑定到$ PORT?我清楚地看到Jetty拿起了端口并且系统上线了吗?
答案 0 :(得分:3)
我知道会发生什么 - 它是经典的IP4 / IP6," localhost"在heroku云计算机上解析为ip6地址。放置0.0.0.0(或者可能也没有按照评论中的建议指定主机)解决了这个问题。