简体   繁体   中英

rails server error `initialize': getaddrinfo: Name or service not known (SocketError)

I am attempting to set up a new Rails app and keep getting the following stack trace:

=> Booting Puma
=> Rails 5.1.0.rc1 application starting in development on http://linux-my4o:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://linux-my4o:9292
Exiting
/home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `initialize': getaddrinfo: Name or service not known (SocketError)
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `new'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `add_tcp_listener'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:105:in `block in parse'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:88:in `each'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:88:in `parse'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/runner.rb:144:in `load_and_bind'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/single.rb:87:in `run'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/launcher.rb:172:in `run'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/rack/handler/puma.rb:64:in `run'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/server.rb:296:in `start'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:44:in `start'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:130:in `block in perform'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:125:in `tap'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:125:in `perform'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/command/base.rb:63:in `perform'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/command.rb:44:in `invoke'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands.rb:16:in `<top (required)>'
        from /home/chris/Projects/cwatsondev-api/bin/rails:9:in `require'
        from /home/chris/Projects/cwatsondev-api/bin/rails:9:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
        from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
        from /home/chris/Projects/cwatsondev-api/bin/spring:15:in `require'
        from /home/chris/Projects/cwatsondev-api/bin/spring:15:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

I've never seen an error like this when running a rails server before. I'm using Rails 5.1.0.rc1 on OpenSuse Tumbleweed. It looks to me like it's having an issue with the hostname linux-my4o.

I figured it out. Just had to add a new line to my etc/hosts file.

127.0.0.1 linux-my4o

I fixed mine by adding the following lines to my environment variables. For linux i added the following line

export HOST="localhost"

if this does not work especially because rails is complaining that the HOST envvar will be depreciated, use this instead

export BINDING="localhost"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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