首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上帝不会阻止独角兽

上帝不会阻止独角兽
EN

Stack Overflow用户
提问于 2012-05-26 01:07:28
回答 1查看 2K关注 0票数 8

我有这个文件

代码语言:javascript
复制
rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = ENV['RAILS_ROOT'] || "/home/luiz/rails_dev/api"

God.watch do |w|
  w.name = "unicorn"
  w.interval = 30.seconds # default

  # unicorn needs to be run from the rails root
  w.start = "cd #{rails_root} && unicorn_rails -c config/unicorn.rb -E #{rails_env}"

  # QUIT gracefully shuts down workers
  w.stop = "kill -QUIT `cat #{rails_root}/tmp/pids/unicorn.pid`"

  # USR2 causes the master to re-create itself and spawn a new worker pool
  w.restart = "kill -USR2 `cat #{rails_root}/tmp/pids/unicorn.pid`"

  w.start_grace = 10.seconds
  w.restart_grace = 10.seconds
  w.pid_file = "#{rails_root}/tmp/pids/unicorn.pid"

  w.behavior(:clean_pid_file)

  w.start_if do |start|
    start.condition(:process_running) do |c|
      c.interval = 5.seconds
      c.running = false
    end
  end

  w.restart_if do |restart|
    restart.condition(:memory_usage) do |c|
      c.above = 300.megabytes
      c.times = [3, 5] # 3 out of 5 intervals
    end

    restart.condition(:cpu_usage) do |c|
      c.above = 50.percent
      c.times = 5
    end
  end

  # lifecycle
  w.lifecycle do |on|
    on.condition(:flapping) do |c|
      c.to_state = [:start, :restart]
      c.times = 5
      c.within = 5.minute
      c.transition = :unmonitored
      c.retry_in = 10.minutes
      c.retry_times = 5
      c.retry_within = 2.hours
    end
  end
end

我用god -c unicorn.god -D -p 8081启动了独角兽,我的员工都设置得很好。但是,有时我确实需要停止独角兽(在另一个控制台中的god stop unicorn -p 8081),但服务器保持运行。

我遗漏了什么?

编辑

我们正在从独角兽到美洲狮(不是因为这个问题,这是一个性能问题),并且不会使用anymore...thanks everybody来帮助你

EN

Stack Overflow用户

回答已采纳

发布于 2013-08-14 20:36:22

现在我们使用foreman和puma,now...this是我们的初始化器:

web: bundle exec puma -q -d -e production -b 'unix:///home/api/shared/web.socket' -S /home/api/shared/web.state --control 'unix:///home/api/shared/web.ctl'

并使用capistrano进行部署,这样我们就可以像这样停止和重新启动服务器

config/deploy.rb

代码语言:javascript
复制
# Puma commands
_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
_cset(:puma_state) { "#{shared_path}/puma.state" }
_cset(:puma_role) { :app }

# Puma
namespace :puma do

  desc 'Start puma'
  task :start do
    run "cd #{current_path} ; bundle exec foreman start web"
  end

  desc 'Stop puma'
  task :stop, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
    run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} stop"
  end

  desc 'Restart puma'
  task :restart, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
    run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} restart"
  end
end
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10758598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档