Command line restore for web only container can't load thor


(Jay Pfaffman) #1

I just tried to do a restore on a web_only container and it whines that it can’t load thor when it tries to load_rails. (If you don’t actually try to restore, it doesn’t fail --and OMG, how awesome is it that it suggests filenames and you can then copy and paste from a list!!! :+1: I don’t know how long that’s been there, but I was psyched to find it.)

root@web-only:/var/www/discourse# script/discourse restore ning-import-2017-08-22-172513-v20170803123704.tar.gz
/usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- thor (LoadError)
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from script/discourse:3:in `<main>'

(Alan Tan) #2

Try bundle exec script/discourse?


(Jay Pfaffman) #3

No joy with bundle exec. Then it can’t connect to the database.

And I tried doing a gem install thor first, but that didn’t solve it either.

And I also tested it on a plain old single-container install. (I didn’t think that was it.)

It used to work: Is there any way to restore your site from backup in the terminal? . And I thought I’d done it recently.


(Alan Tan) #4

What is the exact error?

The gem is installed by default discourse/Gemfile at master · discourse/discourse · GitHub


(Jay Pfaffman) #5

So if you run discourse restore with no arguments, it prints something like this:

You must provide a filename to restore. Did you mean one of the following?

script/discourse restore ipb-import-2017-08-23-165728-v20170605014820.tar.gz
script/discourse restore ipb-import-2017-08-22-180715-v20170605014820.tar.gz

And then if you copy-paste on of those, it runs script/discourse rather tahn discourse, and that doesn’t work.

And I was so excited about the “copy this line” feature.

I’ll submit a PR Real Soon Now.


(Jay Pfaffman) #6

This should do it.


(Alan Tan) #7

I think it would be better if we figure out what the current path is and suggest the appropriate command. Running script/discourse is right if I’m in the /var/www/discourse directory.


(Jay Pfaffman) #8

Sounds right.

Have you done that recently? That’s where I discovered this problem, and why I started the thread. This is for enable_restore, but it’s the same can’t-load-rails problem.

root@discourse:~# cd /var/discourse/
root@discourse:/var/discourse# ./launcher enter app
root@discourse:/var/www/discourse# discourse enable_restore
Expected string default value for '--verbose'; got false (boolean)
Restore are now permitted. Disable them with `disable_restore`
root@discourse:/var/www/discourse# script/discourse enable_restore
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler/runtime.rb:317:in `check_for_activated_spec!': You have already activated thor 0.20.0, but your Gemfile requires thor 0.19.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
        from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler/runtime.rb:32:in `block in setup'
        from /usr/local/lib/ruby/2.3.0/forwardable.rb:204:in `each'
        from /usr/local/lib/ruby/2.3.0/forwardable.rb:204:in `each'
        from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler/runtime.rb:27:in `map'
        from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler/runtime.rb:27:in `setup'
        from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler.rb:101:in `setup'
        from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.3/lib/bundler/setup.rb:9:in `<top (required)>'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
        from /var/www/discourse/config/boot.rb:11:in `<top (required)>'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/www/discourse/config/application.rb:1:in `<top (required)>'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/www/discourse/config/environment.rb:2:in `<top (required)>'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from script/discourse:221:in `load_rails'
        from script/discourse:137:in `enable_restore'
        from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
        from script/discourse:262:in `<main>'
root@discourse:/var/www/discourse# 

(Alan Tan) #9

bundle exec script/discourse is the solution here. The second problem is because you were running bundle exec script/discourse while you were in /var/www/discourse/script instead of /var/www/discourse.


(Jay Pfaffman) #10

So I guess that script/discourse works in a development environment and the discourse wrapper works in production? Is there a way for the script to tell?

And, really, this is a fringe feature that tens of people will probably ever use.

In production, running discourse instead of script/discourse works.

root@discourse-2gb-fra1-01-app:/var/www/discourse# bundle exec script/discourse enable_restore
Expected string default value for '--verbose'; got false (boolean)
bundler: failed to load command: script/discourse (script/discourse)
PG::ConnectionBad: FATAL:  Peer authentication failed for user "discourse"

  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
  /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
  /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/connection_handling.rb:87:in `connection'
  /var/www/discourse/lib/site_settings/db_provider.rb:62:in `table_exists?'
  /var/www/discourse/lib/site_settings/db_provider.rb:21:in `find'
  /var/www/discourse/lib/site_settings/defaults_provider.rb:108:in `block in refresh_site_locale!'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:126:in `block in each_connection'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:124:in `each'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:124:in `each_connection'
  /var/www/discourse/lib/site_settings/defaults_provider.rb:102:in `refresh_site_locale!'
  /var/www/discourse/lib/site_settings/defaults_provider.rb:19:in `initialize'
  /var/www/discourse/lib/site_setting_extension.rb:35:in `new'
  /var/www/discourse/lib/site_setting_extension.rb:35:in `defaults'
  /var/www/discourse/lib/site_setting_extension.rb:69:in `block in setting'
  /var/www/discourse/lib/site_setting_extension.rb:68:in `synchronize'
  /var/www/discourse/lib/site_setting_extension.rb:68:in `setting'
  /var/www/discourse/app/models/site_setting.rb:17:in `block in load_settings'
  /var/www/discourse/lib/site_settings/yaml_loader.rb:25:in `block (2 levels) in load'
  /var/www/discourse/lib/site_settings/yaml_loader.rb:11:in `each'
  /var/www/discourse/lib/site_settings/yaml_loader.rb:11:in `block in load'
  /var/www/discourse/lib/site_settings/yaml_loader.rb:10:in `each_key'
  /var/www/discourse/lib/site_settings/yaml_loader.rb:10:in `load'
  /var/www/discourse/app/models/site_setting.rb:16:in `load_settings'
  /var/www/discourse/app/models/site_setting.rb:21:in `<class:SiteSetting>'
  /var/www/discourse/app/models/site_setting.rb:4:in `<top (required)>'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:360:in `require_or_load'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:494:in `load_missing_constant'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:184:in `const_missing'
  /var/www/discourse/config/initializers/004-message_bus.rb:84:in `<top (required)>'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `load'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `block in load'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `load'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:652:in `block in load_config_initializer'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/notifications.rb:166:in `instrument'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:651:in `load_config_initializer'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:615:in `each'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:615:in `block in <class:Engine>'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `instance_exec'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `run'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
  /usr/local/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
  /usr/local/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
  /usr/local/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
  /usr/local/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
  /usr/local/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:44:in `each'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:44:in `tsort_each_child'
  /usr/local/lib/ruby/2.3.0/tsort.rb:415:in `call'
  /usr/local/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
  /usr/local/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
  /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each'
  /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `call'
  /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
  /usr/local/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
  /usr/local/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/initializable.rb:54:in `run_initializers'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/application.rb:352:in `initialize!'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:194:in `public_send'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:194:in `method_missing'
  /var/www/discourse/config/environment.rb:5:in `<top (required)>'
  script/discourse:221:in `require'
  script/discourse:221:in `load_rails'
  script/discourse:137:in `enable_restore'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
  /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
  script/discourse:262:in `<top (required)>'

Here’s what /usr/local/bin/discourse does:

#!/bin/bash
(cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")