如何用上帝启动rails瘦服务器服务器

时间:2014-05-02 18:49:37

标签: ruby-on-rails ruby god

RAILS_ROOT = File.dirname(File.dirname(__FILE__))

God.watch do |w|
  pid_file = File.join(RAILS_ROOT, "tmp/pids/server.pid")

  w.name = "thin"
  w.interval = 60.seconds
  w.start = "rails server -e production"
  w.stop = "kill -s QUIT $(cat #{pid_file})"
  w.restart = "kill -s HUP $(cat #{pid_file})"
  w.start_grace = 20.seconds
  w.restart_grace = 20.seconds
  w.pid_file = pid_file

  w.behavior(:clean_pid_file)

  # When to start?
  w.start_if do |start|
    start.condition(:process_running) do |c|
      # We want to check if deamon is running every ten seconds
      # and start it if itsn't running
      c.interval = 10.seconds
      c.running = false
    end
  end

我试过w.start =" rails server -e production"但它没有工作说

信息:瘦身移动' up'到了' up' 我[2014-05-02 23:37:09] INFO:瘦[trigger]进程没有运行(ProcessRunning) 我[2014-05-02 23:37:09]信息:瘦身' up'开始'

1 个答案:

答案 0 :(得分:0)

为瘦

创建一个rake任务
namespace :server do
  desc "start thin server"
  task start: :environment do
    puts Rails.root
     `cd #{Rails.root}`
     str  = "rails s -e production"
     puts "Starting server" 
     `#{str}`
  end
end

然后像这样开始

w.start =“cd#{RAILS_ROOT}&& rake server:start”

如果你使用exec rails s -e prodution那么神守护进程将被退出并且你得到服务器unavailbale错误。所以你需要一个rake任务