Unicorn 的 restart 杀不了老的进程,导致每次 deploy 都是 502,得自己手动 kill 谁知道什么原因吗?unicorn.rb 的配置是:
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
old_pid = "#{shared_path}/tmp/unicorn.pid.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
unicorn 你是怎么 restart 的? 这里是 ruby-china 的 deploy.rb
我建议你自行到服务器上执行下面命令,然后通过 ps 查看进程是自动被重启。
cd your/project/path
ps aux | grep unicorn
kill -USR2 `cat #{deploy_to}/current/tmp/pids/unicorn.pid`
ps aux | grep unicorn
注意观察前后 unicorn 的 unicorn master 的 pid 前后跟 tmp/unicorn.pid 是否一致。
upstream yourstorymysong {
server unix:/home/web/apps/yourstorymysong/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80 default;
server_name www.yourstorymysong.com;
root /home/web/apps/yourstorymysong/current/public;
access_log off;
rewrite_log on;
location / {
proxy_pass http://yourstorymysong;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ ^/(assets)/ {
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
}
#7 楼 @LeveyZhu 看不出什么问题,而且你的 Nginx 配置非常规范且完整,怀疑是否是权限的原因。 还有你在主题帖中是否贴出了完整的 unicorn.rb ? 可否对比参考下 ruby-china 的 unicorn.rb ?
另外如果你不通过 cap deploy,而是直接到 server 上,手动执行 kill -USR2 pid
也是一样的问题?