2012-02-05 55 views
1

今天我的头痛! :)管理独角兽实例/导轨部署

我需要一些帮助部署轨道。

我从cherokee迁移到nginx以及,我很轻松地迁移了我的django应用程序。

我只需要启动uwsgi来获取一个tcp套接字并运行我的应用程序。所以我使用supervisord为每个应用程序启动/停止uwsgi套接字。

我想要一些类似于rails的东西。我刚刚开始使用rails,但我希望现在能够部署,因此我将来不会遇到任何问题。

我读了所有几乎所有的互联网和好了,我要问这里:)

我的应用程序生命“的/ srv/HTTP /你好/”

我用麒麟用花哨的配置/麒麟.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 

它的工作原理就像一个魅力。我试图把这个命令放在supervisord中,但是嘿嘿,我问太多了。

因此,具有一定的研究,我发现上帝,所以我挑github上的例子,我把它放在“配置/ 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/[email protected]/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的权限错误。此外,我把“发展”,因为只是一个“轨道新的Hello”

好了,这个工程:

god -c config/god.rb -D 

神推出的麒麟好,在另一端,我可以做“上帝停止麒麟”和有用。

所以问题...

1 - 这是正确的方法吗? 2 - 我是否需要为每个项目配置一个上帝配置,并为每个项目启动上帝进程? 3 - 我如何管理这些上帝的过程?有点像supervisord“supervisorctl restart djangoproject” 4 - 如果我连续三次放入“killall god”,我会死吗? :P 5 - 新问题:如果我说我只需要1个配置所有麒麟实例的神配置,就以某种形式启动它,并且只需要与上帝一起管理它,我就太过分了?上帝开始嘘,上帝开始bleh ...

非常感谢,我只需要开始一个良好的系统管理轨道开发。

回答

0

如果你已经有uWSGI的经验,为什么不使用它的轨道?

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

如果你打算举办了很多的应用程序考虑使用皇帝

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

+0

好主意确实如此。但是,在uWSGI上采用rails兼容性有点麻烦:P – 2012-02-06 12:57:17

+0

有没有办法在uwsgi上使用gemset?我用django使用。 – 2012-02-06 13:41:47

+0

您可以使用GEM_PATH和GEM_HOME环境变量,使用--env选项 – roberto 2012-02-06 16:20:38