In my production environment I have 1 server running as mainappserver (
ex. 10.10.10.10 ) ( Rails + Apache2 + Mysql ) and during heavy periods
we startup a second application server that just handle the Rails
application calls.
The second application server ( ex. 20.20.20.20 ) connects to the mysql
of the mainappserver as specified in the database.yml :
production:
adapter: mysql2
database: appname
username: appuser
password: password
host: 10.10.10.10
encoding: utf8
reconnect: true
Now everytime I’m running a rake tasks or a rails command ( ex. rails
console production ) I get the following error :
Access denied for user ‘appuser’@‘20.20.20.20’ (using password: YES)
It is strange that he is not connecting to the database specified in the
database.yml file. After some research I figured out that one of my
custom plugins is causing the problem. The problem is comming from the
initializer of the plugin where I do :
require “#{File.dirname(FILE)}/lib/fianet_order”
config.to_prepare do
if AppConfig.fianet.enabled
load_fianet
end
end
We need to use the config.to_prepare because we want that it only loads
1 time when it is the production environment and reload everytime in
development mode. In load_fianet we do a class_eval on a model to add
some specific methods.
If I delete this code, the rake tasks and rails commands are working
fine. How does it come that he is not taking the normal database.yml at
this point? It is for the moment also unclear from where he gets the
20.20.20.20 host address to connect to. It is nowhere specified.