Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Rails environement not loaded #141

Open
tbuyle opened this issue Jun 15, 2016 · 6 comments
Open

Rails environement not loaded #141

tbuyle opened this issue Jun 15, 2016 · 6 comments

Comments

@tbuyle
Copy link

tbuyle commented Jun 15, 2016

I have problems running mailman correctly in production as the the Rails environnement is not loaded properly.

The mailman log show that rails is found and loaded :

I, [2016-06-15T09:24:38.616852 #18799]  INFO -- : Mailman v0.7.3 started
I, [2016-06-15T09:24:38.617028 #18799]  INFO -- : Rails root found in ., requiring environment...
I, [2016-06-15T09:24:41.978348 #18799]  INFO -- : IMAP receiver enabled (my.address@domain.com).
I, [2016-06-15T09:24:41.980037 #18799]  INFO -- : Polling enabled. Checking every 60 seconds.

But then, I see errors in the log when processing email : the Rails model are loaded using the development database instead of production.

I tried adding a simple 'puts Rails.env' in the application code and indeed, "development" is returned.

Command used to launch mailman :
RAILS_ENV=production bundle exec mailman -c mailman/mailman-config.rb

mailman/mailman-config.rb:

require "rubygems"
require "bundler/setup"
require 'mailman'
require 'net/imap'

Mailman.config.imap = {
  [IMAP Config]
}

Mailman.config.ignore_stdin = true #used since mailman will eventually be launched as daemon
Mailman.config.logger = Logger.new('log/mailman.log')

Mailman::Application.run do
  default do
      puts Rails.env
      [...]
  end
end
@Mic92
Copy link
Contributor

Mic92 commented Jun 15, 2016

Do you load the the rails environment somewhere?

require File.expand_path('../../config/environment', __FILE__)

@tbuyle
Copy link
Author

tbuyle commented Jun 15, 2016

I tried adding this line on tope of the .rf config file (after the other require).

require File.expand_path('../../config/environment', __FILE__)

Result is the same : Rails.env returns "development" although I use RAILS_ENV=production

@Mic92
Copy link
Contributor

Mic92 commented Jun 15, 2016

Just figured out that, this is already done by mailman:

https://github.com/mailman/mailman/blob/master/lib/mailman/application.rb#L60

And the log you provided reflects the same. As this looks sane I don't know why it loads the wrong environment. You could add a binding.pry just before this line and look if RAILS_ENV is really set correctly.

@denovez
Copy link

denovez commented Jun 17, 2016

in here same problem, please how to run in production environment?

@kirbs-
Copy link

kirbs- commented Nov 6, 2016

I had the same issue. Setting the rails environment with export RAILS_ENV=production, then re-starting mailman solved it for me.

Centos 5.8
ruby 2.2.4
mailman 0.7.3
rails 5.0.0.1

@namangupta01
Copy link

Hey.
I am also getting errors while processing mails in modals in staging environment.

E, [2018-06-21T22:16:37.272427 #1] ERROR -- : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
/usr/local/bundle/gems/mysql2-0.3.21/lib/mysql2/client.rb:70:in `connect'
/usr/local/bundle/gems/mysql2-0.3.21/lib/mysql2/client.rb:70:in `initialize'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/mysql2_adapter.rb:21:in `new'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/mysql2_adapter.rb:21:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in `new_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in `acquire_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_handling.rb:116:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/connection_handling.rb:88:in `connection'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/model_schema.rb:471:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/attributes.rb:233:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/attribute_decorators.rb:50:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/model_schema.rb:464:in `block in load_schema'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/model_schema.rb:461:in `load_schema'
/usr/local/bundle/gems/activerecord-5.1.5/lib/active_record/model_schema.rb:343:in `columns_hash'
/usr/local/bundle/gems/composite_primary_keys-10.0.3/lib/composite_primary_keys/core.rb:30:in `find'
/app/app/models/comment.rb:210:in `receive_mail'
script/mailman_server:24:in `block (2 levels) in <main>'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/router.rb:66:in `instance_exec'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/router.rb:66:in `route'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/message_processor.rb:23:in `block in process'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/middleware.rb:33:in `block in run'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/middleware.rb:38:in `run'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/message_processor.rb:22:in `process'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/receiver/pop3.rb:43:in `block in get_messages'
/usr/local/lib/ruby/2.4.0/net/pop.rb:666:in `each'
/usr/local/lib/ruby/2.4.0/net/pop.rb:666:in `each_mail'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/receiver/pop3.rb:42:in `get_messages'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/application.rb:133:in `block in polling_loop'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/application.rb:130:in `loop'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/application.rb:130:in `polling_loop'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/application.rb:83:in `run'
/usr/local/bundle/gems/mailman-0.7.0/lib/mailman/application.rb:11:in `run'
script/mailman_server:19:in `<main>'

Any idea why it is occuring?
Any help would be appreciated.
Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants