2

看到一个奇怪的问题启动独角兽服务器 -bundle exec ruby unicorn_rails.rb开始没问题,但是当我访问一个 URL 时,它显示:

Mysql2::Error (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2))

所以似乎 unicorn 没有连接到在 database.yml 中配置的远程服务器(因为它试图在本地连接),尽管其他命令,例如bundle exec rails console,工作正常。即使环境设置正确,它似乎也忽略了该设置。这以前可以工作,但有些东西破坏了它。

我把完整的堆栈跟踪放在这里: https ://gist.github.com/mahemoff/6029630

数据库.yml:

staging:
  adapter: mysql2
  database: slide_staging
  host: 192.168.1.255
  port: 3306
  pool: 5
  username: deploy
  password: <%= ENV['DB_PASS'] || "notconfiguredyet" %>
  timeout: 5000
  reconnect: true
4

2 回答 2

1

它可能与独角兽配置有关。

特别是如果您预加载应用程序。你里面有这些线吗?

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

end

after_fork do |server, worker|
  # the following is *required* for Rails + "preload_app true",
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end
于 2013-07-18T14:24:58.667 回答
0

我终于解决了这个问题。事实证明 Rails 环境被覆盖了,因为我引入了一个包含错误的配置片段,使用Rails.env = 'test'而不是Rails.env=='test'. 在注意到我的开发模式在test环境中运行后,我发现了这一点,即使ENV['RAILS_ENV']正确设置为development.

于 2013-07-18T17:10:40.617 回答