2014-10-03 69 views
5

我目前正在开发一个Rails应用程序,作为另一个Rails应用程序的更新程序。从Rails应用程序中用反引号启动另一个Rails服务器

我有更新过程中的工作,

  • 下载新版本的zip
  • 提取到正确的位置
  • 同步资产
  • 捆绑安装
  • 预编译资产
  • 启动服务器 - bundle exec rails server

我遇到了最后一步的问题。

当我运行:

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

从它似乎是从更新器拉更新应用程序捆绑 ,而不是它应该成为拉动新的应用程序包。

的更新是写在轨道4和应用程序是更新是轨道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 #<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>' 

从这个输出,我可以告诉它试图使用不正确的railties版本...

当我手动cd ../other-projectbundle exec rails server -d -p 3000它工作正常。

是否有任何可用于解决此问题的bash技巧? 基盒是Ubuntu 14.04

谢谢!

+0

为什么使用整个rails应用程序来执行这个程序任务?您可以使用bash脚本完成此操作 – kendotwill 2014-10-06 22:38:46

+0

@kendotwill此应用程序的目的是为嵌入式rails应用程序提供前端更新程序/控制器。这两种轨道应用都​​运行在一个流浪箱中。一个bash脚本可以工作,但用户无法按需更新。 – 2014-10-07 02:25:22

回答

6

好的,我花了早上排除故障,我找到了解决方案!

所有你需要做之前设置BUNDLE_GEMFILE环境变量:

bundle exec rails server -d -p 3000

看来,捆扎机需要一些帮助寻找项目的Gemfile因为我试图启动中的另一个应用程序当前包,这里是我创建的类来控制此更新程序将负责更新的应用程序。

我很高兴地说,启动方法终于按预期工作!

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 
+2

您可能还会发现Bundler.with_clean_env有趣 – 2014-10-06 16:15:16

+0

@FrederickCheung我喜欢这一点,看起来比我的解决方案更清洁 – 2014-10-07 12:09:23

0

你是对的Mike!

我会说只是设置端口:

bundle exec rails s -p 3001

bundle exec rails s -p 3000

两个不同的服务器实例!

干杯!

相关问题