使用反引号从Rails应用程序中启动另一个Rails服务器
我目前正在开发一个Rails应用程序,作为另一个Rails应用程序的更新程序。
我有更新过程,
- 下载新版本zip
- 提取到正确的位置
- 同步资产
- 捆绑安装
- 预编译资产
- 启动服务器 – bundle exec rails server
我在最后一步遇到了问题。
当我跑:
Dir.chdir('../other-project') `bundle exec rails server -d -p 3000`
从更新程序应用程序,它似乎是从更新程序包中提取而不是它应该从中提取的新应用程序包。
更新程序是用Rails 4编写的,它正在更新的应用程序是rails 3。
当我尝试启动服务器时,我得到以下内容:
/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 # (NoMethodError) from /home/vagrant/apps/other-project/config/application.rb:22:in `' from /home/vagrant/apps/other-project>' from /home/vagrant/apps/other-project/config/application.rb:13:in `' 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 `' from script/rails:6:in `require' from script/rails:6:in `'
从这个输出我可以告诉它它正试图使用不正确版本的铁路…
当我手动cd ../other-project
和bundle exec rails server -d -p 3000
它工作正常。
我可以使用任何bash技巧来解决这个问题吗? 基本框是Ubuntu 14.04
谢谢!
好吧,我花了一个上午对此进行故障排除,我找到了解决方案!
您所要做的就是在以下之前设置BUNDLE_GEMFILE环境变量:
bundle exec rails server -d -p 3000
看来Bundler需要一些帮助来找到项目Gemfile,因为我正在尝试在当前包中启动另一个应用程序,这是我创建的用于控制应用程序的类,此更新程序将负责更新。
我很高兴地说start方法最终按预期工作!
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
你是对的迈克!
我会说只是设置端口:
bundle exec rails s -p 3001
bundle exec rails s -p 3000
为两个不同的服务器实例!
干杯!
- rails 4- 401未经授权的error handling
- PG :: ConnectionBad FATAL:角色“Myname”不存在
- 2 activeadmin的命名空间
- 设计:从用户模型中获取和设置区域设置
- Rails ActiveRecord模型has_one两次到具有不同外键的相同模型
- 如何在heroku上的两个不同的应用程序之间共享工作者?
- 什么是最酷的Ruby on Railsfunction,为什么选择它?
- Rails Engines – 简单可能的引擎(1)添加模型和(2)在包含类中添加关联
- nested_form,collection_select,accepts_nested_attributes_for和fields_for,并将记录添加到连接表