Rails console starting in development mode

154 views
Skip to first unread message

Miroslav Schlossberg

unread,
Oct 13, 2019, 1:33:47 PM10/13/19
to alavet...@googlegroups.com
Hi everyone,
On the new VM box after migration, rails console is started in development mode while I have STAGING set to 0 in general.yml.

This is what I get when starting console (Alaveteli v0.30.0.0, Ubuntu 14.04):

$ bundle exec rails console

Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.

Running via Spring preloader in process 23438

Loading development environment (Rails 4.2.9)

irb: warn: can't alias context from irb_context.


Any ideas how to fix it and force this to run always in production mode? Same as with all other bundle and RoR items.

Thanks!

Cheers,
Miroslav

photo
Miroslav Schlossberg
Code for Croatia

--------------------------------------------
Q: Why is this email [hopefully] three sentences or less?

NOTE that my emails are delayed from arriving in my inbox until 5pm daily (Central European Time). If urgent, please use another way of getting in touch. #slowwebmovement

Miroslav Schlossberg

unread,
Oct 13, 2019, 5:05:31 PM10/13/19
to alavet...@googlegroups.com
Update:
When I add RAILS_ENV=production I get following error:

$ bundle exec rails console RAILS_ENV=production

Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.

config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:


  * development - set it to false

  * test - set it to false (unless you use a tool that preloads your test environment)

  * production - set it to true



/home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection': 'RAILS_ENV=production' database is not configured. Available: ["default", "development", "test", "production"] (ActiveRecord::AdapterNotSpecified)

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:211:in `resolve_connection'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_handling.rb:50:in `establish_connection'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/railtie.rb:122:in `block (2 levels) in <class:Railtie>'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/lazy_load_hooks.rb:27:in `each'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/lazy_load_hooks.rb:27:in `on_load'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/railtie.rb:118:in `block in <class:Railtie>'

from /home/alaveteli/bundle/ruby/1.9.1/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `instance_exec'

from /home/alaveteli/bundle/ruby/1.9.1/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `run'

from /home/alaveteli/bundle/ruby/1.9.1/gems/railties-4.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'

from /usr/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'

from /usr/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'

from /usr/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'

from /usr/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'

from /usr/lib/ruby/1.9.1/tsort.rb:180:in `each'

from /usr/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'

from /usr/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'

from /home/alaveteli/bundle/ruby/1.9.1/gems/railties-4.2.9/lib/rails/initializable.rb:54:in `run_initializers'

from /home/alaveteli/bundle/ruby/1.9.1/gems/railties-4.2.9/lib/rails/application.rb:352:in `initialize!'

from /var/www/imamopravoznati.org/alaveteli/config/environment.rb:6:in `<top (required)>'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'

from /home/alaveteli/bundle/ruby/1.9.1/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'

from /home/alaveteli/bundle/ruby/1.9.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'

from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

from -e:1:in `<main>'


In alaveteli config environments I have following:

~/alaveteli/config/environments$ ls -al

total 28

drwxr-xr-x 2 alaveteli alaveteli 4096 Oct  5 07:33 .

drwxr-xr-x 5 alaveteli alaveteli 4096 Oct 13 06:27 ..

-rw-r--r-- 1 alaveteli alaveteli 2557 Oct  5 07:33 development.rb

-rw-r--r-- 1 alaveteli alaveteli 4717 Oct  5 07:33 production.rb

-rw-r--r-- 1 alaveteli alaveteli  954 Oct  5 07:33 staging.rb

-rw-r--r-- 1 alaveteli alaveteli 2290 Oct  5 07:33 test.rb


Cheers,
Miroslav

photo
Miroslav Schlossberg
Code for Croatia

--------------------------------------------
Q: Why is this email [hopefully] three sentences or less?

NOTE that my emails are delayed from arriving in my inbox until 5pm daily (Central European Time). If urgent, please use another way of getting in touch. #slowwebmovement

Gareth Rees

unread,
Oct 14, 2019, 5:11:13 AM10/14/19
to Alaveteli Dev
One of the deployment tasks is to copy a file to `APP_ROOT/config/rails_env.rb` [1], which is designed to always force the app in to production mode.

You need to add this file to the shared directory that Capistrano creates.

Not sure why it wasn't created, but you can create it easily enough [2]:

    echo "ENV['RAILS_ENV'] ||= 'production'" > rails_env.rb

Gareth Rees

unread,
Oct 14, 2019, 5:12:57 AM10/14/19
to Alaveteli Dev
It looks like the production database isn't set up?

    /home/alaveteli/bundle/ruby/1.9.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:248:in
    `resolve_symbol_connection': 'RAILS_ENV=production' database is not configured. Available: ["default", "development", "test", "production"]
    (ActiveRecord::AdapterNotSpecified)

I think add the `rails_env.rb` file and get that working first and see where you get to with that.

Miroslav Schlossberg

unread,
Oct 14, 2019, 2:47:40 PM10/14/19
to alavet...@googlegroups.com
Hi Gareth,
Thank you! I didn't have file file rails_env.rb (I also didn't see it on my old server), so I have done as you wrote. (and restarted alaveteli afterwards) But still console is opened in a development mode:

alaveteli@ImamoPravoZnati-v2:~/alaveteli$ bundle exec rails console

Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.

Running via Spring preloader in process 24336

Loading development environment (Rails 4.2.9)

irb: warn: can't alias context from irb_context.

irb(main):001:0> 


I'm getting this error regarding Rubygems version. I'm also getting this error for all cronjobs via email:

---------- Forwarded message ---------
From: Cron Daemon
Date: Mon, Oct 14, 2019 at 1:48 PM
Subject: Cron <alaveteli@ImamoPravoZnati-v2> /var/www/imamopravoznati.org/alaveteli/commonlib/bin/run-with-lockfile.sh -n /var/www/imamopravoznati.org/send-batch-requests.lock /var/www/imamopravoznati.org/alaveteli/script/send-batch-requests || echo "stalled?"
To: email
Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
Running via Spring preloader in process 120261

I was hoping to see this message gone after switching to Production env.

Thing is that I didin't run any scripts/migrations after we migrated alaveteli to new server. 
Would it hurt now to run "rake db:migrate"? Or even "script/rails-post-deploy"?

What we did:
- installed via install script alaveteli v0.30.0.0 (https://alaveteli.org/docs/installing/script/)
- confirmed that new install is working fine on new server
- transferred directories (files, cache, logs)
- transferred pg dump and restored db
- transferred general.yml and database.yml
- enabled READ ONLY mode on the app
- started the app

So I assumed it should work with all these steps.

admin/debug says all is good:

Version numbers
Alaveteli version: 0.30.0.0
Alaveteli branch: release/0.30.0.0
Alaveteli commit: ce785e903962c75f369b0c18c4d0fefc1f327972
RUBY_VERSION 1.9.3
Rails::VERSION::STRING 4.2.9
Xapian::version_string 1.2.21
 
Configuration
Rails env: production
Rails root: /var/www/imamopravoznati.org/alaveteli

Issues we had right after migration:
- public bodies list was there on new web (OK)
- but requests were not visible on web (NOK), but visible on admin interface
-> I fixed it by running Xapian reindex
- now I have issue that new emails piped to alaveteli are not visible on alaveteli (maybe the reason is development/production mode? or does READ ONLY mode blocks receiving of new emails piped to alaveteli via postfix?)

So how to switch alaveteli from current development mode to production mode? I thought STAGING parameter in general.yml should do it.

p.s. I didn't managed to get Capistrano fully running, on each deploy I had tons of errors, so I decided to go with normal install on new server and to deal with capistrano later.

Thank you!

Cheers,
Miroslav

photo
Miroslav Schlossberg
Code for Croatia

--------------------------------------------
Q: Why is this email [hopefully] three sentences or less?

NOTE that my emails are delayed from arriving in my inbox until 5pm daily (Central European Time). If urgent, please use another way of getting in touch. #slowwebmovement

--
You received this message because you are subscribed to the Google Groups "Alaveteli Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alaveteli-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/alaveteli-dev/064e7d24-f586-4daf-8c8e-3f8bef757208%40googlegroups.com.

Miroslav Schlossberg

unread,
Oct 14, 2019, 3:05:29 PM10/14/19
to alavet...@googlegroups.com
Hi Gareth,
So, I did this:

$ sudo -u alaveteli RAILS_ENV=production \

>   /var/www/imamopravoznati.org/alaveteli/script/rails-post-deploy


And it seems to resolved issue with starting console correctly in production mode:

$ sudo -u alaveteli bundle exec rails console

Loading production environment (Rails 4.2.9)

irb(main):001:0>



Cheers,
Miroslav

photo
Miroslav Schlossberg
Code for Croatia

--------------------------------------------
Q: Why is this email [hopefully] three sentences or less?

NOTE that my emails are delayed from arriving in my inbox until 5pm daily (Central European Time). If urgent, please use another way of getting in touch. #slowwebmovement

Reply all
Reply to author
Forward
0 new messages