Hi!
I can't figure out why Sidekiq tries to connect to postgresql on localhost on my production machine, when my config/database.yml has production settings that point to a db on AWS, which the Rails application is using ok. I have tried initialising sidekiq and from both command line and upstart methods. I start it with the -e production flag, and also have RAILS_ENV=production set on the machine. I am also printing out Rails.env from within my worker to verify that environment is indeed production. Yet, everytime my worker gets called, the log reports that Sidekiq cannot connect to the db:
Here is a snip from sidekiq.log
2015-03-02T08:46:33.108Z 2176 TID-otfjtdvgo INFO: Running in ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
2015-03-02T08:46:33.108Z 2176 TID-otfjtdvgo INFO: See LICENSE and the LGPL-3.0 for licensing details.
2015-03-02T08:46:33.108Z 2176 TID-otfjtdvgo INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org/pro
2015-03-02T08:46:33.108Z 2176 TID-otfjtdvgo INFO: Starting processing, hit Ctrl-C to stop
2015-03-02T08:46:33.135Z 2176 TID-otfkbnln4 INFO: Booting Sidekiq 3.3.2 with redis options {}
2015-03-02T08:46:33.135Z 2176 TID-otfkdm1n8 INFO: Booting Sidekiq 3.3.2 with redis options {}
2015-03-02T08:46:41.958Z 2176 TID-otfkdo0rs SmsServiceWorker JID-13796c217334c7c15a047fec INFO: start
2015-03-02T08:46:41.959Z 2176 TID-otfkdo0rs SmsServiceWorker JID-13796c217334c7c15a047fec INFO: Environment is production
2015-03-02T08:46:41.959Z 2176 TID-otfkdo0rs SmsServiceWorker JID-13796c217334c7c15a047fec INFO: SmsServiceWorker starting new job
2015-03-02T08:46:41.962Z 2176 TID-otfkdo0rs SmsServiceWorker JID-13796c217334c7c15a047fec INFO: fail: 0.004 sec
2015-03-02T08:46:41.963Z 2176 TID-otfkdo0rs WARN: {"retry"=>false, "queue"=>"default", "class"=>"SmsServiceWorker", "args"=>["example", "3601", "ae1de47d61dea6066a2709d04e636e72"], "jid"=>"13796c217334c7c15a047fec", "enqueued_at"=>1425286001.9568455}
2015-03-02T08:46:41.963Z 2176 TID-otfkdo0rs WARN: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2015-03-02T08:46:41.963Z 2176 TID-otfkdo0rs WARN: /var/www/example-api/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/var/www/example-api/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
database.yml
default: &default
adapter: postgresql
encoding: UTF-8
pool: 5
test:
<<: *default
host: localhost
database: example_test
development:
<<: *default
database: example_development
host: localhost
# stored on the server at /etc/environment
staging:
<<: *default
database: example_staging
host: <%= ENV['DATABASE_HOST'] %>
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
production:
<<: *default
database: example_production
host: <%= ENV['DATABASE_HOST'] %>
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
Any help is greatly appreciated.
Paul
No idea.
Are you using dotenv or something similar, @paul-ylz ? I'm having this issue with dotenv
@PedroSena I was storing parameters in /etc/environment. My issue was solved by adding source /etc/environment before initializing sidekiq in the upstart .conf file.
Thanks @paul-ylz , I moved my parameters to the same file and now it is working as it should, however I'm not using dotenv on production anymore
Most helpful comment
No idea.