Home > Software engineering >  Rails server fails to start without any error message
Rails server fails to start without any error message

Time:01-14

I use Ruby on Rails to develop a website, my env is Win10, Ubuntu 18.04 LTS, Rails 6.1.4.4, Ruby 2.6.6p146 and PostgreSQL 10.19. Whenever I want to start a website rails server on my local machine, the browser can't find the page, the only solution is to reboot, but I'm fed up with this crappy solution.

I've noticed that if I start (rails server) a website that uses PostgreSQL without first starting the PostgreSQL server (with sudo service postgresql start), WSL abnormally doesn't give any error messages, still a start-up message (below) is printed. Of course, even if I remember to follow all the steps, the browser may still not open the page.

This makes me wonder if there's something wrong with the environment setting that prevents me from seeing the error message that should be there, so that I don't know why the rails server is failing?

Here is my WSL message at the time:

$ rails s
/home/k/.rvm/rubies/ruby-2.6.6/bin/ruby: warning: shebang line ending with \r may cause problems
=> Booting Puma
=> Rails 6.1.4.4 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.5.2 (ruby 2.6.6-p146) ("Zawgyi")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 220
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop

CodePudding user response:

It is okay because ActiveRecord won't establish database connection until needed.

One way to fail if PostgreSQL is not started is to add these lines to config/environments/development.rb

  config.after_initialize do
    ActiveRecord::Base.connection
  end
  •  Tags:  
  • Related