unicorn/resqueã®ããã»ã¹ç®¡çã«eyeã使ã
unicorn,resqueã®ããã»ã¹ç®¡çã«ä»åã¯eyeã使ããã¨ã«ãã¾ãã ã¯ããBluepillã§è¨å®ãã¦ããã®ã§ãããRuby2.0ç°å¢ã ã¨Bluepillã®ããã»ã¹ãã¾ã³ãã§æºã¾ãã¾ããã¨ããåé¡ãããã代æ¿ããããã¦ããã¨ããeyeã¨ããã®ãããã¾ãããGodãBluepillãåèã«ä½ããã¦ããã¨ãããã¨ã§è¨å®ãä¼¼ãæãããªï¼ã¨æãæ¡ç¨ãã¦ãã¾ããä»ã®ã¨ããRuby2.xç°å¢ã§ãåé¡ã¯èµ·ãã¦ãã¾ããã
Eyeã¨Monitã§ç£è¦å¯¾è±¡ã®ããã»ã¹ãããã
ãããã¤ã®éã«åèµ·åããããã»ã¹ãeyeã§ããã以å¤ãmonitã§ç£è¦ããããã«ãã¾ãã
ã¤ã³ã¹ãã¼ã«
bundleã§ã¯ç¡ãgemã§å
¥ãã¦ã¾ãã
$gem install eye
eyeã®èµ·åæ¹æ³ã¯eye load è¨å®ãã¡ã¤ã«
ã¨ãªãã¾ãã
è¨å®ãã¡ã¤ã«ã¯ãµã¼ãã®å½¹å²æ¯ã«ç¨æãã¦ããã¾ãã
åãµã¼ãã«ç°å¢å¤æ°SERVER_ROLE
ã¨ããã®ãè¨å®ãã¦ãã¦ããã®ç°å¢å¤æ°ããèªã¿è¾¼ãè¨å®ãã¡ã¤ã«ã決ã¾ããããã¾ãã
ããã§appsãµã¼ãã¯unicornãèµ·åããè¨å®ãèªã¿è¾¼ã¿ãresqueãµã¼ãã¯resqueé¢é£ãèµ·åããè¨å®ãèªã¿è¾¼ããã¨ã«ãªãã¾ãã
eyeã®è¨å®ãã¡ã¤ã«
Railsããã¸ã§ã¯ãã®config/eye/以ä¸ã«è¨å®ãã¡ã¤ã«ãããããé ç½®ãã¦ããã¾ããã 以ä¸ã¯unicornã¨resque-workerããã»ã¹ã管çããè¨å®ä¾ã«ãªãã¾ãã åããã»ã¹ã®èµ·ååæ¢ã³ãã³ãããç£è¦å 容ãè¨å®ãã¦ãã¾ãï¼ããã»ã¹ã®ã¡ã¢ãªã300mè¶ ãããåèµ·åããã¨ãï¼
- config/eye/staging-app.eye
# -*- coding: utf-8 -*- ENV['RAILS_ROOT'] ||= File.expand_path(File.join(File.dirname(__FILE__), "../..")) rails_root = ENV['RAILS_ROOT'] rails_env = ENV['RAILS_ENV'] stage = ENV['STAGE'] current_path = "/home/ec2-user/example/#{stage}/current" shared_path = "/home/ec2-user/example/#{stage}/shared/" # load submodules, here just for example Eye.load("./eye/*.rb") # Eye self-configuration section Eye.config do logger "/var/log/eye/eye.log" end Eye.application "#{stage}-app" do working_dir current_path process("unicorn") do pid_file "tmp/pids/unicorn.pid" start_command "bundle exec unicorn -Dc config/unicorn/#{stage}.rb -E #{rails_env}" stdall "log/unicorn.log" # stop signals: # http://unicorn.bogomips.org/SIGNALS.html stop_signals [:TERM, 10.seconds] # soft restart restart_command "kill -USR2 {PID}" check :cpu, :every => 30, :below => 99, :times => 3 check :memory, :every => 30, :below => 300.megabytes, :times => [3,5] start_timeout 120.seconds restart_grace 120.seconds monitor_children do stop_command "kill -QUIT {PID}" check :cpu, :every => 30, :below => 99, :times => 3 check :memory, :every => 30, :below => 300.megabytes, :times => [3,5] end end process ("resque_worker") do pid_file "tmp/pids/resque_worker.pid" start_command "bundle exec rake -t -f Rakefile environment resque:work" stop_signals [:QUIT, 5.seconds,:TERM, 5.seconds,:KILL] start_timeout 120.seconds restart_grace 120.seconds daemonize false env "RAILS_ENV" => rails_env, "QUEUE" => "*", "INTERVAL" => 1, "BACKGROUND" => "yes", "PIDFILE" => "tmp/pids/resque_worker.pid" stdall "log/resque_worker.log" monitor_children do stop_command "kill -QUIT {PID}" check :cpu, :every => 30, :below => 99, :times => 3 check :memory, :every => 30, :below => 300.megabytes, :times => [3,5] end end end
ãããã¤ã¿ã¹ã¯ãç¨æãã
ãããã¤æã«unicorn,resqueã®åèµ·åãå¿ è¦ã«ãªãã®ã§ãeyeãéãã¦åèµ·åãè¡ããããã«ã¿ã¹ã¯ãæ¸ãã¦ããã¾ãã ãªããunicornã®åèµ·åã«ã¯USR2ã§ã®ãªã¹ã¿ã¼ãã¨ããã»ã¹ãè½ã¨ãã¦èµ·åããã®ï¼ã¤ã®æ¹æ³ã§åèµ·åã§ããããã«ããããã¿ã¹ã¯ãç¨æãã¾ããã (ãã¡ã¤ã«ã¢ãããã¼ãã®ãããã¤æã¯USR2ãªãã¼ãã§è¯ããcurrentã·ã³ããªãã¯ãªã³ã¯ãåãæ¿ããå ´åã¯åæ¢ãèµ·åãè¡ãã¾ã)
- cap staging deploy:reload - eye restartãå®è¡ããã(unicornã®USR2ãªãã¼ã)
- cap staging deploy:restart - eye stop,startãå®è¡ããã)
lib/capistrano/tasks/eye.cap
namespace :eye do desc "eye start" task :start do on roles(:app), in: :parallel do execute "sudo /etc/init.d/eye start || true" end end desc "eye stop" task :stop do on roles(:app), in: :parallel do execute "sudo /etc/init.d/eye stop || true" end end desc "eye restart" task :restart do on roles(:app), in: :sequence, wait: 10 do execute "sudo /etc/init.d/eye restart || true" end end desc "eye stop and start" task :stop_start do on roles(:app), in: :sequence, wait: 20 do |host| puts host if host.roles.include?(:web) execute "ssh gateway elb_remove.rb #{fetch(:stage)} #{host} || true" end execute "sudo /etc/init.d/eye stop || true" execute "sudo /etc/init.d/eye start || true" puts "sleep 30" sleep 30 if host.roles.include?(:web) execute "ssh gateway elb_add.rb #{fetch(:stage)} #{host} || true" end end end desc "eye info" task :info do on roles(:app), in: :parallel do count = 0 while capture("sudo /etc/init.d/eye info || true").match(/starting/) && count < 18 puts "loop" count = count + 1 sleep 10 end end end after :restart, "eye:info" after :stop_start, "eye:info" end