2012-02-05 57 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