繁体   English   中英

管理独角兽实例/ Rails部署

[英]Managing unicorn instances / rails deployment

今天头好痛! :)

我需要一些有关Rails部署的帮助。

我从切诺基迁移到nginx,然后,我轻松地迁移了django应用。

我只需要启动uwsgi即可获得tcp套接字并运行我的应用程序。 因此,我使用超级用户来启动/停止每个应用程序的uwsgi套接字。

我想要类似的导轨。 我刚开始使用Rails,但是我希望现在就可以部署,这样以后就不会有问题了。

我读了几乎所有的互联网,而且,我不得不在这里问:)

我的应用程序位于“ / srv / http / hello /”中

我用花哨的config / unicorn.rb使用独角兽

worker_processes 2
working_directory "/srv/http/hello/"

# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true

timeout 30

# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/srv/http/hello/tmp/sockets/unicorn.sock", :backlog => 64

pid "/srv/http/hello/tmp/pids/unicorn.pid"

# Set the path of the log files inside the log folder of the testapp
stderr_path "/var/log/unicorn/hello-stderr.log"
stdout_path "/var/log/unicorn/hello-stdout.log"

before_fork do |server, worker|
# This option works in together with preload_app true setting
# What is does is prevent the master process from holding
# the database connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
# Here we are establishing the connection after forking worker
# processes
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

我只是改编了一些互联网示例。

如果我运行类似:

unicorn_rails -c config/unicorn.rb -D

它像一种魅力。 我试图将这个命令放在主管的监督下,但是,我要求太多了。

因此,通过一些研究,我发现了上帝,所以我选择了github的示例,并将其放在“ config / god.rb”上(这是个好地方吗?)

# http://unicorn.bogomips.org/SIGNALS.html

rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = ENV['RAILS_ROOT'] || "/srv/http/hello"

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} && /srv/http/.rvm/gems/ruby-1.9.3-p0@hello/bin/unicorn_rails -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"

  # 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.uid = 'http'
  #w.gid = 'webgroup'

  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

注意:自从http用户启动uid和gid以来,我已经对其进行了注释,或者在编写pid时出现权限错误。 我也说“发展”,因为这只是“新的问候”

好的,这可行:

god -c config/god.rb -D

上帝发射了独角兽好,在另一个终端,我可以做“上帝阻止独角兽”,它的工作原理。

所以问题...

1-这是正确的方法吗? 2-我是否需要为每个项目配置一个God配置,并为每个项目启动God配置进程? 3-我该如何管理那些神的过程? 有监督的“ supervisorctl restart djangoproject”之类的东西4-如果连续放置3次“ killall god”,我会死吗? :P 5-新问题:如果我说我只需要1个配置所有独角兽实例的神,以某种形式启动它并用神来管理它,那太过分了吗? 上帝开始等等,上帝开始……

非常感谢,我只需要通过良好的系统管理就可以开始Rails开发。

如果您已经有uWSGI的使用经验,为什么不也将其用于rails?

http://projects.unbit.it/uwsgi/wiki/RubyOnRails

如果您打算托管很多应用,请考虑使用Emperor

http://projects.unbit.it/uwsgi/wiki/Emperor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM