rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Mega mode does not start rack app on port 9292 automatically #114

Closed zeetao closed 5 years ago

zeetao commented 5 years ago

I followed the instructions for Mega Mode from https://blog.boltops.com/2018/11/03/jets-mega-mode-run-rails-on-aws-lambda I created a new project, and then linked my rails project, watched jets pull the rails project into the rack folder. I tested the rack app using bundle exec rackup from the rack folder and see my rails app being run on port 9292. When I run jets server, I see the webrick server on port 8888 come up, but the error below indicates the rack app at 9292 isn't started. If I start it manually, then jets server manages to connect to 9292 but then it takes a terribly long time to serve assets. God knows why. Seems like there is a configuration step missing from the docs.

be jets server
=> bundle exec shotgun --port 8888 --host 127.0.0.1
Jets booting up in development mode!
=> cd ./rack && bin/rackup --host 127.0.0.1
sh: bin/rackup: No such file or directory
== Shotgun/WEBrick on http://127.0.0.1:8888/
== Shotgun/WEBrick on http://127.0.0.1:8888/
[2018-12-23 10:46:16] INFO  WEBrick 1.4.2
[2018-12-23 10:46:16] INFO  WEBrick 1.4.2
[2018-12-23 10:46:16] INFO  ruby 2.5.1 (2018-03-29) [x86_64-darwin14]
[2018-12-23 10:46:16] INFO  ruby 2.5.1 (2018-03-29) [x86_64-darwin14]
bundler: failed to load command: shotgun (/Users/rrr/.rbenv/versions/2.5.1/bin/shotgun)
Errno::EADDRINUSE: Address already in use - bind(2) for 127.0.0.1:8888
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:201:in `bind'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:201:in `listen'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:764:in `block in tcp_server_sockets'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:227:in `each'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:227:in `foreach'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/socket.rb:762:in `tcp_server_sockets'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/utils.rb:65:in `create_listeners'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/server.rb:127:in `listen'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/server.rb:108:in `initialize'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:47:in `initialize'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:31:in `new'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:31:in `run'
  /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/bin/shotgun:156:in `<top (required)>'
  /Users/rrr/.rbenv/versions/2.5.1/bin/shotgun:23:in `load'
  /Users/rrr/.rbenv/versions/2.5.1/bin/shotgun:23:in `<top (required)>'
[2018-12-23 10:46:16] INFO  WEBrick::HTTPServer#start: pid=4901 port=8888
I, [2018-12-23T10:46:29.214519 #4908]  INFO -- : Started GET "/" for  at 2018-12-23 10:46:29 +0800
I, [2018-12-23T10:46:29.214698 #4908]  INFO -- : Processing Jets::RackController#process
I, [2018-12-23T10:46:29.215200 #4908]  INFO -- :   Event: {"resource":"/{catchall+}","path":"/","httpMethod":"GET","headers":{"Host":"localhost:8888","Connection":"keep-alive","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-GB,en-US;q=0.9,en;q=0.8","Version":"HTTP/1.1","cache-control":"max-age=0","upgrade-insecure-requests":"1"},"queryStringParameters":{},"pathParameters":{"catchall":""},"stageVariables":null,"requestContext":{},"body":null,"isBase64Encoded":false}
I, [2018-12-23T10:46:29.215437 #4908]  INFO -- :   Parameters: {"catchall":""}
Errno::ECONNREFUSED: Failed to open TCP connection to localhost:9292 (Connection refused - connect(2) for "localhost" port 9292)
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:935:in `connect'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:909:in `start'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1455:in `request'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/mega/request.rb:47:in `proxy'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/internal/app/controllers/jets/rack_controller.rb:23:in `mega_request'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/internal/app/controllers/jets/rack_controller.rb:7:in `process'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/controller/base.rb:41:in `dispatch!'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/controller/middleware/local.rb:34:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/jets-1.4.2/lib/jets/middleware.rb:12:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/lint.rb:49:in `_call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/lint.rb:37:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/show_exceptions.rb:23:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/common_logger.rb:33:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/lib/shotgun/loader.rb:86:in `proceed_as_child'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/lib/shotgun/loader.rb:31:in `call!'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/lib/shotgun/loader.rb:18:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/lib/shotgun/favicon.rb:12:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shotgun-0.9.2/lib/shotgun/static.rb:14:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:68:in `block in call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `each'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:153:in `call'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:86:in `service'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:140:in `service'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:96:in `run'
    /Users/rrr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'
127.0.0.1 - - [23/Dec/2018:10:46:29 +0800] "Get / HTTP/1.1" 500 97168 0.0863
tongueroo commented 5 years ago

Looking at the error message. It looks like bin/rackup is missing. That should get generated as part of jets import:rails, so that's odd.

=> cd ./rack && bin/rackup --host 127.0.0.1
sh: bin/rackup: No such file or directory

RE: but then it takes a terribly long time to serve assets. God knows why.

This is likely due to hot-reloading and having lots of assets or files to load. You can start the server up with --no-reload but then you'll have to restart the server manually when you make changes. Hot-reloading is an area that would like to be improved. Happy to take pull requests on this. 👌

Anyway, though Mega Mode is still around, a better version of Rails support was released in Jets v1.4+ Here are the links:

Please have a look at that. The flow is much more simple. Glad to hear you're trying this approach though.

zeetao commented 5 years ago

I am trying all kinds of things to discover the capabilities of Jets. I will try to this afterburner method. I would still want to try to deploy my static site to aws directly. Not sure why bin/rackup isn't there. What can I do to fix this?

Zee

On Sun, 23 Dec 2018 at 11:27, Tung Nguyen notifications@github.com wrote:

Looking at the error message. It looks like bin/rackup is missing. That should get generated as part of jets import:rails, so that's odd.

=> cd ./rack && bin/rackup --host 127.0.0.1

sh: bin/rackup: No such file or directory

RE: but then it takes a terribly long time to serve assets. God knows why.

This is likely due to hot-reloading and having lots of assets or files to load. You can start the server up with --no-reload but then you'll have to restart the server manually when you make changes. Hot-reloading is an area that would like to be improved. Happy to take pull requests on this. 👌

Anyway, though Mega Mode is still around, a better version of Rails support was released in Jets v1.4+ Here are the links:

Please have a look at that. The flow is much more simple. Glad to hear you're trying this approach though.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tongueroo/jets/issues/114#issuecomment-449611856, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDK7DD98wmU3hj2Sxw3x7gtoHneWNoVks5u7vgogaJpZM4ZfsAE .

tongueroo commented 5 years ago

Right, so as mentioned in #105 , think that this full port approach is going to be a bit of work. I mentioned this in the Ruby on Rails Podcast Episode #253 also. Think Jets makes a great use case for microservices and glue code. It's cool that you're doing a full port to learn also, and am sure you'll learn a lot. It is a lot of work though.

Would like to improve this. And would be awesome if someone wants to help in this area. For example, one key improvement is to allow view helpers to handle model objects. No sweat either way 👌

Here's just a suggestion: generate a new jets app from scratch from the quick start. Then slowly go piece by piece from there instead of copying your whole enchilada over and then fixing afterward. In this way you get a few errors little by little and can tackle one at a time systematically, learning along the way.

Also from the new app and running a jets import:rails, you can grab the bin/rackup from there.