Launch another Rails server from a Rails application with feedback

I am currently working on a Rails application that serves as an update to another Rails application.

I have an update process,

  • Download new zip version
  • Pull to the right place
  • Sync assets
  • Package installation
  • Precompile Assets
  • Start server with - bundle exec rails server

I have a problem with the last step.

When I run:

Dir.chdir('../other-project') `bundle exec rails server -d -p 3000` 

from the updater application, it seems, it is pulled from the service pack and not the new application package from which it should be extracted.

The updater is written in Rails 4, and the updated application is rails 3.

When I try to start the server, I get the following:

 /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `handlebars' for #<Rails::Application::Configuration:0x007f9de18de100> (NoMethodError) from /home/vagrant/apps/other-project/config/application.rb:22:in `<class:Application>' from /home/vagrant/apps/other-project>' from /home/vagrant/apps/other-project/config/application.rb:13:in `<top (required)>' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in `require' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in `block in server' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!' from /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' 

From this conclusion, I can say that he is trying to use the wrong version of railties ...

When I manually cd ../other-project and bundle exec rails server -d -p 3000 works fine.

Are there any bash tricks that I can use to get around this? Base Box - Ubuntu 14.04

Thanks!

+5
source share
2 answers

Ok, I spent the morning solution to this problem and I found a solution!

All you have to do is set the BUNDLE_GEMFILE environment variable before:

bundle exec rails server -d -p 3000

It seems that the Bundler needs a little help finding Gemfile projects, as I try to run another application in the current package, here is the class I created to manage the application, which this updater will be responsible for updating.

I am pleased to say that the launch method finally works as expected!

 class AppController @dir = Rails.root.join('../', 'Other-app/') def self.running? File.exist?("#{@dir}/tmp/pids/server.pid") end def self.start if running? puts "app already running" else Dir.chdir(@dir) puts "starting app..." `BUNDLE_GEMFILE=Gemfile bundle exec rails server -d -p 3000` puts "app started" end end def self.kill if not running? puts "app already dead" else Dir.chdir(@dir) puts "killing app..." `kill $(cat tmp/pids/server.pid)` puts "app dead" end end def self.restart if running? kill start else start end end end 
+6
source

You're right Mike!

I will say that I just installed the port:

bundle exec rails s -p 3001

bundle exec rails s -p 3000

for two different server instances!

Hurrah!

0
source

Source: https://habr.com/ru/post/1203967/


All Articles