私は数日後にユニコーンインスタンスを破損しているように見える中規模のEC2インスタンスを持っており、アプリケーションが403エラーをスローし、URLが次のように表示されますhttp://app/foo/bar
「app」はユニコーンへのプロキシです。これがnginxの私のサイト構成です
upstream app {
server unix:/home/foo/app/shared/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80; # This is on by default.
client_max_body_size 2G;
# upload_max_file_size 50m;
server_name foo.tld; # Hostname
keepalive_timeout 5;
root /home/foo/app/current/public; # Application root.
access_log /home/foo/log/foo_access.log; # Logs for nginx access
error_log /home/foo/log/foo_error.log;
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$) {
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
# Static serving as defined in the RoR guides
# http://guides.rubyonrails.org/asset_pipeline.html#in-production
location ~ ^/(assets(?!\/(files|pictures)))/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
# Proxy forwarding to unicorn
location / {
try_files $uri/index.html $uri.html $uri @app;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
location ~ \.php {
deny all;
}
}
私のユニコーン.rb
worker_processes 4
working_directory '/home/foo/app/current'
# 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
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
timeout 30
# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen '/home/foo/app/shared/sockets/unicorn.sock', :backlog => 64
pid '/home/foo/app/shared/pids/unicorn.pid'
# Set the path of the log files inside the log folder of the testapp
stderr_path '/home/foo/app/current/log/unicorn.stderr.log'
stdout_path '/home/foo/app/current/log/unicorn.stdout.log'
そして私のキャップレシピ
require 'bundler/capistrano'
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
require "rvm/capistrano" # Load RVM's capistrano plugin.
# Application name
set :application, "foo"
# Repo information
set :repository, "foo.git"
set :scm, :git
set :branch, "master"
# Server information
set :user, "foo"
set :scm_passphrase, "foo"
set :deploy_via, :remote_cache
server "foo.tld", :web, :app, :db # This is our EC2 Instance
set :deploy_to, "/home/foo/app"
ssh_options[:keys] = [File.join(ENV["HOME"], "keys/foo")]
set :use_sudo, false
namespace :deploy do
desc "Restart of Unicorn"
task :restart, :excerpt => { :no_release => true } do
run "kill -a USR2 `cat /home/foo/app/shared/pids/unicorn.pid`"
end
desc "Start Unicorn"
task :start, :excerpt => { :no_release => true } do
run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -E production -D"
end
desc "Stop Unicorn"
task :stop, :excerpt => { :no_release => true } do
run "kill -s QUIT `cat /home/foo/app/shared/pids/unicorn.pid`"
end
namespace :web do
desc "Throw maintenance page up"
task :disable do
require "erb"
on_rollback { run "rm #{shared_path}/system/maintenance.html" }
reason = ENV['REASON']
deadline = ENV['UNTIL']
template = File.read("./app/views/layouts/maintenance.html.erb")
result = ERB.new(template).result(binding)
put result, "#{shared_path}/system/maintenance.html", :mode => 0644
end
end
end
なぜユニコーンが数日後に行動を起こすのかについての洞察はありますか? さらに、現在のセットアップに「落とし穴」はありますか?
更新: ユニコーンはハングアップしたプロセスを再起動できないようです
E, [2012-07-03T09:59:13.554781 #9521] ERROR -- : worker=3 PID:9656 timeout (31s > 30s), killing
E, [2012-07-03T09:59:13.710103 #9521] ERROR -- : reaped #<Process::Status: pid 9656 SIGKILL (signal 9)> worker=3
I, [2012-07-03T09:59:13.710349 #9521] INFO -- : worker=3 spawning...
I, [2012-07-03T09:59:13.906277 #16214] INFO -- : worker=3 spawned pid=16214
I, [2012-07-03T09:59:13.906672 #16214] INFO -- : worker=3 ready
E, [2012-07-03T13:37:45.158213 #9521] ERROR -- : worker=3 PID:16214 timeout (31s > 30s), killing
E, [2012-07-03T13:37:45.402827 #9521] ERROR -- : reaped #<Process::Status: pid 16214 SIGKILL (signal 9)> worker=3
I, [2012-07-03T13:37:45.403125 #9521] INFO -- : worker=3 spawning...
I, [2012-07-03T13:37:45.531584 #16270] INFO -- : worker=3 spawned pid=16270
I, [2012-07-03T13:37:45.531982 #16270] INFO -- : worker=3 ready