Start another Rails Server from within Rails App with backticks

≡放荡痞女 提交于 2019-12-05 10:45:33

Alright, I've spent the morning troubleshooting this and I found a solution!

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

bundle exec rails server -d -p 3000

It seems that Bundler needs a little help finding the projects Gemfile since I'm trying to start another app within the current bundle, here is the class that I created to control the app that this updater will be responsible for updating.

I'm happy to say that the start 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

You are right Mike !!

I'll say just set port :

bundle exec rails s -p 3001

bundle exec rails s -p 3000

for two different server instance!

Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!