Unicorn 在接收 USR2 时是否保留相同的 PID?

Unicorn 在接收 USR2 时是否保留相同的 PID?

因此,我一直在个人服务器上使用 unicorn 部署。这背后有多种原因 - 其中之一是我并不特别想编译自己的 nginx 版本来获取 phusion 乘客。(我喜欢对事物进行包管理。)

无论如何,unicorn 表现出一些奇怪的行为。当您向 Unocorn 发送 USR2 信号时,它应该通过将其 pid 文件从 unicorn.pid 复制到 unicorn.pid.oldbin 来本质上进行热交换。我已经配置了我的 unicorn.rb 文件,以便如果它在启动时找到所述 unicorn.pid.oldbin - 它会将旧进程标记为 QUIT - 就像我应该做的那样。

但是,这似乎不起作用,因为没有任何 PID 发生变化。因此,要么是 Unicorn 继承了相同的 PID,要么是出了什么问题。

下面是 Unicorn 主进程的 strace。我不是壮观阅读系统调用 - 但我没有看到任何让我眼前一亮的东西。有人能看看并告诉我我遗漏了什么吗?谢谢!

Process 32177 attached - interrupt to quit
select(6, [5], NULL, NULL, {20, 476644}) = ? ERESTARTNOHAND (To be restarted)
--- SIGUSR2 (User defined signal 2) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
fcntl64(6, F_GETFL)                     = 0x1 (flags O_WRONLY)
fcntl64(6, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
write(6, ".", 1)                        = 1
select(6, [5], NULL, NULL, {10, 814939}) = 1 (in [5], left {10, 814936})
fcntl64(5, F_GETFL)                     = 0 (flags O_RDONLY)
fcntl64(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
read(5, ".", 11)                        = 1
waitpid(-1, 0xbf987ee4, WNOHANG)        = 0
open("/www/web/tmp/unicorn.pid.oldbin", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
open("/www/web/tmp/unicorn.pid", O_RDONLY|O_LARGEFILE) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=6, ...}) = 0
fstat64(4, {st_mode=S_IFREG|0644, st_size=6, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb777c000
_llseek(4, 0, [0], SEEK_CUR)            = 0
read(4, "32177\n", 4096)                = 6
read(4, "", 4096)                       = 0
close(4)                                = 0
munmap(0xb777c000, 4096)                = 0
unlink("/www/web/tmp/unicorn.pid") = 0
open("/www/web/tmp/0.0132033250636285.32177", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = 4
fcntl64(4, F_GETFL)                     = 0x8002 (flags O_RDWR|O_LARGEFILE)
fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb777c000
_llseek(4, 0, [0], SEEK_CUR)            = 0
write(4, "32177\n", 6)                  = 6
rename("/www/web/tmp/0.0132033250636285.32177", "/www/web/tmp/unicorn.pid.oldbin") = 0
close(4)                                = 0
munmap(0xb777c000, 4096)                = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb74939d8) = 32184
waitpid(-1, 0xbf987ee4, WNOHANG)        = 0
gettimeofday({1312941623, 777508}, NULL) = 0
gettimeofday({1312941623, 777684}, NULL) = 0
select(6, [5], NULL, NULL, {26, 0})     = ? ERESTARTNOHAND (To be restarted)
--- SIGCHLD (Child exited) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
fcntl64(6, F_GETFL)                     = 0x801 (flags O_WRONLY|O_NONBLOCK)
write(6, ".", 1)                        = 1
select(6, [5], NULL, NULL, {25, 595766}) = 1 (in [5], left {25, 595763})
fcntl64(5, F_GETFL)                     = 0x800 (flags O_RDONLY|O_NONBLOCK)
read(5, ".", 11)                        = 1
waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG) = 32184
gettimeofday({1312941624, 183506}, NULL) = 0
write(2, "reaped #<Process::Status: pid=32"..., 57) = 57
open("/www/web/tmp/unicorn.pid", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
open("/www/web/tmp/unicorn.pid.oldbin", O_RDONLY|O_LARGEFILE) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=6, ...}) = 0
fstat64(4, {st_mode=S_IFREG|0644, st_size=6, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb777c000
_llseek(4, 0, [0], SEEK_CUR)            = 0
read(4, "32177\n", 4096)                = 6
read(4, "", 4096)                       = 0
close(4)                                = 0
munmap(0xb777c000, 4096)                = 0
unlink("/www/web/tmp/unicorn.pid.oldbin") = 0
open("/www/web/tmp/0.712879319799392.32177", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = 4
fcntl64(4, F_GETFL)                     = 0x8002 (flags O_RDWR|O_LARGEFILE)
fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb777c000
_llseek(4, 0, [0], SEEK_CUR)            = 0
write(4, "32177\n", 6)                  = 6
rename("/www/web/tmp/0.712879319799392.32177", "/www/web/tmp/unicorn.pid") = 0
close(4)                                = 0
munmap(0xb777c000, 4096)                = 0
waitpid(-1, 0xbf987ee4, WNOHANG)        = 0
gettimeofday({1312941624, 186901}, NULL) = 0
gettimeofday({1312941624, 187058}, NULL) = 0
select(6, [5], NULL, NULL, {25, 0}^C <unfinished ...>
Process 32177 detached

答案1

我找到了解决这个问题的方法。

事实证明,我的日志文件中有一些我遗漏的消息,这些消息表明新子进程的启动过程失败了。失败的原因是我没有在 Gemfile 中声明 unicorn。

出于某种原因,似乎可以在 Gemfile 中不存在 unicorn 的情况下从命令行启动 unicorn,但如果 Gemfile 中没有提及 unicorn,则无法启动自身。

我很想听听知道原因的人对此的解释,但目前我的问题已经解决了。我可以成功循环独角兽了。

答案2

我一直在处理相关问题,我们仍在邮件列表中处理该问题:http://rubyforge.org/pipermail/mongrel-unicorn/2011-August/001081.html

相关内容