Connection refused (PGError) (postgresql and rails) - ruby-on-rails

I keep getting this error when i try to run my localhost using "$rails s":
(Mac OSX 10.8.3)
(ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0])
(Rails 3.2.11)
(psql (PostgreSQL) 9.2.2 ) **installed with homebrew
I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start.
I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash.
Here is the output when I run "rails s" in the terminal
Danny$ rails s
^[b=> Booting Thin
=> Rails 3.2.11 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could not connect to server: Connection refused (PGError)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5433?
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__3642716200177086041__prepare__4186317719333288752__callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/Danny/Dropbox/programming/coding/f_app/config/environment.rb:7:in `<top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:3:in `block in <main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `new'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `<main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

The error message is instrumental:
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
port
You may be trying to connect to the wrong port.
Standard port is 5432. Check how (and whether at all) you started your postgres server:
postgres#db:~$ ps -auxww | grep ^postgres
... <stripped more lines>
postgres 1274 0.0 0.3 1437240 57308 ? S May27 5:01 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
The manual has related information here.
In my example, settings from /etc/postgresql/9.1/main/postgresql.conf got used, which says (among many other settings):
port = 5432
Or run:
netstat -nlp | grep postgres
Or just look here (at least in Debian or Ubuntu):
ls -lA /var/run/postgresql/
PostgreSQL picks the next free port if you create a new database cluster. Since you installed repeatedly, you may have confused port numbers.
listen_addresses
Or you just forgot to allow TCP/IP connections. Related answers:
Run batch file with psql command without password
What's the difference between "local" and "localhost" connection types in pg_hba.conf?
no pg_hba.conf entry for host

This may resolve the issue :-
Get the hba.conf file address by using command SHOW config_file; and SHOW hba_file; in sql prompt
Now open hba.conf and add this host all all 0.0.0.0/0 trust
Now open postgresql.conf and add listen_address = '*'

In my case, the problem was caused by the upgrade of postgresql-9.4 to postgresql-9.5 in Ubuntu 16.04. Since, There were two versions installed at some point in time, the later installed version i.e. postgresql-9.5's config changed to default port of 5433 (instead of standard default 5432).
The problem occurred when my Rails project tried to connect to the default port of postgresql (since the port was not defined explicitly defined in database.yml file) and kept failing. Even after removal of postgresql-9.4 later.
Solution changing postgresql's config file
The solution is changing the port in the configuration of updated postgresql (9.5). To do this open the file /etc/postgresql/9.5/main/postgresql.conf and change the line
port = 5433 # (change requires restart)
to
port = 5432 # (change requires restart)
and then restart the server with sudo service postgresql restart.
Solution with changing Rails' `database.yml' file
Alternatively, you can change rails' database.yml file by explicitly mention the new port (that ie 5433) without changing the postgresql's config file. To do this, simply add a line like this
port: 5433
and restart the rails server.

sudo -u postgres pg_ctlcluster 9.3 main stop
followed by
sudo -u postgres pg_ctlcluster 9.3 main restart
worked for me

I got this error message hooking up to Jira (from the Jira side) and the solution was to change the "Hostname or IP address of the database server." to "localhost". If you're running locally you can't just put in your local ip address.
Also the next issue for a local install is the password always fails even though that's correct because pg_hba.conf needs to be edited so the authentication method is "trust".

In postgresql.conf, /var/lib/pgsql/data/postgresql.conf :
change the listen_addresses = 'localhost' to listen_addresses = '*'
enable the default port as 5432, port = 5432
Also in pg_hba.conf, /var/lib/pgsql/data/pg_hba.conf,
try the authentication method as trust

Related

Ruby on Rails - Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)

When I attempt to start my rails server from my local machine, I get the following error message.
/Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `new'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `add_tcp_listener'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:105:in `block in parse'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:88:in `each'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:88:in `parse'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/runner.rb:144:in `load_and_bind'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/cluster.rb:391:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/rack/handler/puma.rb:69:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/server.rb:297:in `start'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/server.rb:104:in `start'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `server'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/zachdobbs/sample_app/bin/rails:9:in `require'
from /Users/zachdobbs/sample_app/bin/rails:9:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/zachdobbs/sample_app/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
This error occurred suddenly and I'm not sure what the cause of it could be. When I looked online I noticed that the issue could be another service running on the port 3000, but when I try and run 'lsof -i tcp:3000' I get no results.
Within puma.rb, I define.
port ENV.fetch("PORT") { 3000 }
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
When I change the port value to something such as 8080 the server will run. I am confused as to why the server will not launch on port 3000. Every command I have attempted to run has shown me no services running on that port.
I know this is a really old post but I had to answer just in case others get here as I did.
When you declare port or bind commands in the puma config it will try to bind to all those ports or addresses.
In this case you've specified port twice so it's trying to bind to both and the second one will fail.
Try the following:
> sudo ps ax | grep rails
#1338 pts/1 Sl+ 0:06 /usr/bin/ruby2.3 bin/rails c
#1707 pts/0 Rl+ 0:07 /usr/bin/ruby2.3 bin/rails s
> sudo kill -9 1707
> rails s
For me, the solution was pretty easy. But please be aware that (as the command says) shuts down ALL instances of ruby. You could solve it more fine-grained than this, e.g. with a strategy like Abhi mentioned.
killall ruby
All other things didn't help me:
killall rails
# -> rails: no process found
killall puma
# -> puma: no process found
You can also consider these possibly related Q/A:
Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)
jekyll 2.2.0 | Error: Address already in use - bind(2)

Rails-tutorial Chapter 1: rails server isn't working on Cloud9

https://www.railstutorial.org/book/beginning#sec-rails_server
I have reached this step, and I'm using the cloud9 environment. When I run the server as per Listing 1.7 on that tutorial, however, I get this error:
myname#rails-tutorial:~/workspace/hello_app $ rails server -p $PORT -b $IP
=> Booting WEBrick
=> Rails 4.2.0.beta2 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-10-30 21:44:22] INFO WEBrick 1.3.1
[2014-10-30 21:44:22] INFO ruby 2.1.1 (2014-02-24) [x86_64-linux]
Exiting /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `listen'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `each'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `foreach'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:132:in `listen'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `new'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `run'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/server.rb:288:in `start'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ubuntu/workspace/hello_app/bin/rails:8:in `require'
from /home/ubuntu/workspace/hello_app/bin/rails:8:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ubuntu/workspace/hello_app/bin/spring:16:in `require'
from /home/ubuntu/workspace/hello_app/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
I've tried specifying a different port, but that doesn't work and the cloud9 environment suggests to me I should just use the $PORT variable.
The error "Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)" implies that I already have a rails server running, but I don't. I'm not really sure what to do here and the tutorial doesn't suggest any method of troubleshooting this issue.
I learned that you can use the command killall ruby to stop any of the ruby processes which helped me because I had mistakenly run the rails server -b $IP -p $PORT command at the ~/workspace level in the tutorial. I found the answer in can't open rails server
I ended up starting the tutorial from scratch again and it worked fine, but anyone with this problem in the future may find this troubleshooting technique I received from cloud9's support team useful:
Try:
lsof -i:8080
This will give the app that occupies it.
If apache, stop it using:
sudo /etc/init.d/apache2 stop
Hope this answer is of use to anyone with this problem.
Probably you just had the other server still running. The one you initiate earlier on in he tutorial with the rails server command. You need to shut the other one down first using Ctrl+C, then try rails server -b $IP -p $PORT again
$ rails server -b $IP -p $PORT
Cloud9 uses the special environment variables $IP and $PORT to assign
the IP address and port number dynamically. If you want to see the
values of these variables, type echo $IP or echo $PORT at the command
line.
It's likely that if you wait a few minutes (not more than 2), your OS will free up the port. If not, use a random port number over about 5,000 every time you run rails server, e.g.
$ rails server -b $IP -p 6789
Or, because your IDE is so sucky, you might consider using a different IDE.

Ruby on Rails: Bad connection with PG after running rake:db migrate

Recently I forked and cloned a repo I am contributing to and when I run rails s I get no errors, however when I run rake db:migrate I get this.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I checked out some other threads with other people who had the same problem however their solutions did not really have any luck for me.
I tried uninstalling and reinstalling PG as well as getting rid of the .PID file however it doesn't look like I seem to have one.
Any clues, pointers or advice? Thanks in advance.
This means either your database.yml file in config/ directory is not set up correctly for your environment, most likely development as it is the default or you do not have postgresql running.
If you do not have postgresql running either install it or start it up. You can check postgresql, more than likely with either:
sudo service postgresql status
or
ps -ef | grep postgres
If you do have postgresql running, then check your database.yml file and edit it appropriately, most likely something like:
development:
adapter: postgresql
encoding: unicode
database: database_name
host: localhost
username: user_name
password: password

NetSSh Gem , Start method producing Connection TimedOut Error

In my Project, I'm testing the connection with remote Windows 2008 server, through ssh. I'm always getting the following error:
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `initialize'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `open'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `block in initialize'
from /home/kamesh/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /home/kamesh/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/timeout.rb:97:in `timeout'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:67:in `initialize'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `new'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `start'
from /home/kamesh/projects/RubyApp/lib/connections/ssh_connection.rb:9:in `connect'
from (irb):5
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
To ensure, what we're talking about the same thing - here's a link to Net::SSH GitHub page.
According to your error message, your ssh client can't connect to ssh server on another host.
First, you need to ensure that your server has server running. Here's a guide about how to install it on Windows Server 2008.
Second, you need to try and ping your server, to ensure if it's accessible through your network at all.
If there weren't any problems on previous stages, you can try to use Net::SSH again.

Rails 3 Server crashes on start: "Not a socket file descriptor"

I'm trying to get started with Ruby on Rails, and it's all gone quite well up until I try to start the server. I get the following error:
C:\Users\Ken\workspace\railsHello>rails server
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-03-10 19:53:08] INFO WEBrick 1.3.1
[2011-03-10 19:53:08] INFO ruby 1.9.2 (2011-02-18) [i386-mingw32]
[2011-03-10 19:53:09] WARN TCPServer Error: not a socket file descriptor
Exiting
C:/Ruby192/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize': not a socket file
descriptor (ArgumentError)
from C:/Ruby192/lib/ruby/1.9.1/webrick/utils.rb:73:in `new'
from C:/Ruby192/lib/ruby/1.9.1/webrick/utils.rb:73:in `block in create_l
isteners'
from C:/Ruby192/lib/ruby/1.9.1/webrick/utils.rb:70:in `each'
from C:/Ruby192/lib/ruby/1.9.1/webrick/utils.rb:70:in `create_listeners'
from C:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:74:in `listen'
from C:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:62:in `initialize'
from C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:24:in `initialize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/handler/web
rick.rb:10:in `new'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/handler/web
rick.rb:10:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:2
13:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/comman
ds/server.rb:65:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/comman
ds.rb:30:in `block in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/comman
ds.rb:27:in `tap'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/comman
ds.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
C:\Users\Ken\workspace\railsHello>
I don't even know where to start with "TCPServer Error: Not a socket file descriptor."
Trying it through Aptana didn't help either.
I'm on Windows 7 Home Premium. Apache was already installed, but I shut it down and it didn't make a difference.
Thanks in advance for your help!
-Ken
Are you sure nothing else is listening on port 3000 (perhaps an old instance of the server that didn't get shut down)? Check the following:
netstat -a -b
If there is, simply kill that application, or start WEBrick on another port; for example, to start it on port 8000:
rails server --port=8000

Resources