Unable to deploy my ROR application to fly.io - ruby-on-rails

This is my first experience deploying a rails application to production. I want to deploy to Fly.io and have created credentials and initiated files fly.io configuration files for deployment. But when I deploy I get the following error:
Starting init (commit: f447594)...
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=af164c5a-e60d-4061-98ea-5d4af379bce2
Preparing to run: `bin/rails fly:release` as root
2023/01/01 07:53:05 listening on [fdaa:1:1737:a7b:80:5bf5:b65f:2]:22 (DNS: [fdaa::3]:53)
Is the server running on host "::1" and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
/app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
....
...
...
/app/vendor/bundle/ruby/3.1.0/gems/activerecord-
1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
Tasks: TOP => fly:release => db:migrate
(See full trace by running task with --trace)
Starting clean up.
Error release command failed, deployment aborted
I followed the instructions given by Chris Oliver from GoRails & Deanin but that wasn't of any help as they can get it up & running with just a couple of commands. I believe my issue is in my config/database/yml file but I am able to figure out the specifics.
Any ideas on how should I debug this problem?

Related

Issues connecting with server for postgres db - trying to understand why

I am working on rails project which I've cloned from GitHub. Because of other commitments, I have not been able to program for ~6 months, so I may have had an OSX update in this time.
I am getting an issue which I see others have had:
➜ isengarden git:(develop) rails db:create
could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'isengarden_development' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/joshua/code/JoshInLisbon/rails-projects/isengarden/bin/rails:9:in `<top (required)>'
/Users/joshua/code/JoshInLisbon/rails-projects/isengarden/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
postgres.log:
2021-01-07 14:22:42.358 WET [86720] FATAL: database files are incompatible with server
2021-01-07 14:22:42.358 WET [86720] DETAIL: The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.1.
I am trying the solutions that have been set out on StackOverflow, but I would really like to know what is going on under the hood to make this error happen.
I have quite a limited understanding of DB fundamentals, so for me a problem like this is in a very opaque space, where I'm just copying and pasting solutions without an idea of why they might work.
Can anyone explain what is likely happening, and what the actual meaning is of my postgres logs?
Thank you
The version you have installed on your local computer is different from the postgres version with which the project was generated, when you change different versions you must be careful, since some functions are deprecated or renamed, in addition to the structure or form in which the data is saved also changes.
The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.1.
I suggest you install postgres version 11 and if you want to work with 13.1 then you must generate a backup and download it to a database generated with the current version

Running localhost:3000 using Ruby on rails with pgadmin3 database i get following errors

Can anyone help me fix this problem?? when i run localhost:3000 i encounter this?
"could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?..... Now, again when i try to run "net start postgresql-9.5" in CMD line it says
'system error 5 has occured,access is denied'.
what is wrong i cant understand?
I know in windows it's struggling to learn rails but if you want to continue below is some tips when I test running rails with windows
for rails installer, you can download from http://railsinstaller.org/en it include git , ruby and rails
for postgres, I think it's easier to install from this site, you just follow windows instruction and make sure you write down the password as you will need it later for your database.yml (database configuration)
after you install both programs, when you want to open command prompt, make sure you choose command prompt with ruby on rails, as this command prompt will include git, ruby and rails command.
hopefully can help

rails db:migrate causing Errno::ECONNRESET, Connection reset by peer during capistrano deployment

We are having an issue with ssh level connection error, seems to be a timeout, during long deployments running our capistrano deploy with a large rails db migration task. Our only help has been moving these to rake tasks we manually run after deploy, not ideal. Any ideas within ruby/rails stack or outside to ensure ssh connection stays alive?
Errno::ECONNRESET, Connection reset by peer
Full trace:
** [deploy:update_code] exception while rolling back: Errno::ECONNRESET, Connection reset by peer - recvfrom(2)
/Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/net-ssh-2.9.2/lib/net/ssh/buffered_io.rb:65:in `recv': Connection reset by peer - recvfrom(2) (Errno::ECONNRESET)
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/net-ssh-2.9.2/lib/net/ssh/buffered_io.rb:65:in `fill'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:237:in `block in postprocess'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:233:in `each'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:233:in `postprocess'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/processable.rb:33:in `block in process_iteration'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/processable.rb:45:in `block in ensure_each_session'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/processable.rb:43:in `each'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/processable.rb:43:in `ensure_each_session'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/processable.rb:31:in `process_iteration'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/command.rb:171:in `block (2 levels) in process!'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/command.rb:170:in `loop'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/command.rb:170:in `block in process!'
from /Users/Ben/.rvm/rubies/ruby-1.9.3-p550/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
from /Users/Ben/.rvm/gems/ruby-1.9.3-p550#/gems/capistrano-2.15.5/lib/capistrano/command.rb:169:in `process!'
"Connection reset by peer" usually means that either the software on the remote end of the connection has crashed, or else some stateful firewall between the client and the server is interfering with the TCP connection.
In this case, the remote software ought to be the SSH server. And you say that this happens on long deployments. Given these things, I'd suspect that you have a NAT device or other stateful firewall between the client and the server, and it's dropping the TCP connection after some period.
You could try setting your client to send keepalive packets. I'm not a Ruby developer, but this page describes a keepalive option. Aside from that, you should talk to your network engineers to see if anything can be done about the device which is interfering with the connection.
So hopefully this helps someone else, think I found answer to my own question.
In our situation we had web and worker boxes both getting new deployment via capistrano. The web boxes were doing more expensive long running tasks like assets compile and publish to AWS S3 bucket. While this was happening our worker boxes became idle and timed out from no activity. capistrano detected this as an overall failure and rolls back release.
There are a few options here, like compiling rails asset pipeline resources ahead of time and even publishing to aws first, then starting other deployment steps.
We opt'd to just have our server's do client ping keep alives at ssh level
sudo vim /etc/ssh/sshd_config
Add these two lines to file:
ClientAliveInterval 60
ClientAliveCountMax 200
Note some sites mention just the first one, I found it didnt' work well unless putting second one also, as I suspect default max count is low.
ensure to restart ssh service after the change on each deployment target machine.
Just run rake db:migrate on your project before deploying it on server and after that run rake production deploy.

Can not run console on Heroku, or run any commands

I'm unable to connect to Heroku's console as I could in the past using:
$ heroku run rails console
The result of that is:
Running `rails console` attached to terminal... up, run.4695
!
! Timeout awaiting process
Following a Heroku guide, I issued this command..
$ telnet rendezvous.runtime.heroku.com 5000
and the result was:
Trying 50.19.103.36...
telnet: connect to address 50.19.103.36: Operation timed out
telnet: Unable to connect to remote host
I switched to another ISP recently, and I have verified with their tech support that they don't block access to any ports (including 5000). So, I really don't know what's going on.
What else can I do? I sincerely need help.
Thanks in advance,
Kind Regards,

How to allow multiple rails apps access to local postgreSQL database

I am new to Ruby/Rails and PostgreSQL. Is it possible to have to multiple rails apps access a psql local database at the same, if not how do you switch between applications?
Currently RailsApp1 is interacting with my psql db as expected, however RailsApp2 cannot connect and rake commands abort.
Running on: OSX Mountain Lion, ruby 1.9.3p194, rails 3.2.8, psql 9.2.1.
~/RailsApp2 #: rake db:migrate
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Thank you in advance for the help.
PostgreSQL uses a client-server model, so the fact is you just connect to the server and multiple applications can make it work. Your specific problem sounds like the server isn't running or isn't accepting connections. Steps to try in order:
ps -A | grep post looking for postgres or postmaster processes. If not found start the server using the pg_ctl program.
Assuming it is running try setting the PGHOST environment variable to "localhost" so that it forces rake, psql, etc. to connect over TCP/IP. This would help if the UNIX socket is missing or just not where the client apps expect it to be.
If those two fail, find your postgresql logs (sometimes called serverlog, and sometimes in a pg_log directory) and post error messages.

Resources