13

我试图了解如何用上帝来监控 resque 工人的travis-ci,这样通过上帝停止 resque 手表不会留下陈旧的工人进程。

下面我说的是工作进程,而不是分叉的作业子进程(即队列一直是空的)。

当我像这样手动启动 resque worker 时:

$ QUEUE=builds rake resque:work

我将得到一个进程:

$ ps x | grep resque
 7041 s001  S+     0:05.04 resque-1.13.0: Waiting for builds

一旦我停止工作任务,这个过程就会消失。

但是当我用上帝开始同样的事情时(确切的配置在这里,与resque/god 示例基本相同)像这样......

$ RAILS_ENV=development god -c config/resque.god -D
I [2011-03-27 22:49:15]  INFO: Loading config/resque.god
I [2011-03-27 22:49:15]  INFO: Syslog enabled.
I [2011-03-27 22:49:15]  INFO: Using pid file directory: /Volumes/Users/sven/.god/pids
I [2011-03-27 22:49:15]  INFO: Started on drbunix:///tmp/god.17165.sock
I [2011-03-27 22:49:15]  INFO: resque-0 move 'unmonitored' to 'init'
I [2011-03-27 22:49:15]  INFO: resque-0 moved 'unmonitored' to 'init'
I [2011-03-27 22:49:15]  INFO: resque-0 [trigger] process is not running (ProcessRunning)
I [2011-03-27 22:49:15]  INFO: resque-0 move 'init' to 'start'
I [2011-03-27 22:49:15]  INFO: resque-0 start: cd /Volumes/Users/sven/Development/projects/travis && rake resque:work
I [2011-03-27 22:49:15]  INFO: resque-0 moved 'init' to 'start'
I [2011-03-27 22:49:15]  INFO: resque-0 [trigger] process is running (ProcessRunning)
I [2011-03-27 22:49:15]  INFO: resque-0 move 'start' to 'up'
I [2011-03-27 22:49:15]  INFO: resque-0 moved 'start' to 'up'
I [2011-03-27 22:49:15]  INFO: resque-0 [ok] memory within bounds [784kb] (MemoryUsage)
I [2011-03-27 22:49:15]  INFO: resque-0 [ok] process is running (ProcessRunning)
I [2011-03-27 22:49:45]  INFO: resque-0 [ok] memory within bounds [784kb, 784kb] (MemoryUsage)
I [2011-03-27 22:49:45]  INFO: resque-0 [ok] process is running (ProcessRunning)

然后我会得到一个额外的过程:

$ ps x | grep resque
 7187   ??  Ss     0:00.02 sh -c cd /Volumes/Users/sven/Development/projects/travis && rake resque:work
 7188   ??  S      0:05.11 resque-1.13.0: Waiting for builds
 7183 s001  S+     0:01.18 /Volumes/Users/sven/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Volumes/Users/sven/.rvm/gems/ruby-1.8.7-p302/bin/god -c config/resque.god -D

上帝似乎只记录了第一个的pid:

$ cat ~/.god/pids/resque-0.pid
7187

然后当我通过上帝停止 resque 手表时:

$ god stop resque
Sending 'stop' command

The following watches were affected:
  resque-0

上帝给出了这个日志输出:

I [2011-03-27 22:51:22]  INFO: resque-0 stop: default lambda killer
I [2011-03-27 22:51:22]  INFO: resque-0 sent SIGTERM
I [2011-03-27 22:51:23]  INFO: resque-0 process stopped
I [2011-03-27 22:51:23]  INFO: resque-0 move 'up' to 'unmonitored'
I [2011-03-27 22:51:23]  INFO: resque-0 moved 'up' to 'unmonitored'

但它实际上并没有终止这两个进程,而是让实际的工作进程保持活动状态:

$ ps x | grep resque
 6864   ??  S      0:05.15 resque-1.13.0: Waiting for builds
 6858 s001  S+     0:01.36 /Volumes/Users/sven/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Volumes/Users/sven/.rvm/gems/ruby-1.8.7-p302/bin/god -c config/resque.god -D
4

2 回答 2

17

您需要告诉上帝使用救援生成的pid文件并设置pid文件

w.env = {'PIDFILE' => '/path/to/resque.pid'}
w.pid_file = '/path/to/resque.pid'

env 会告诉rescue 写pid 文件,pid_file 会告诉god 使用它

也正如 svenfuchs 指出的那样,只设置适当的环境就足够了:

w.env = { 'PIDFILE' => "/home/travis/.god/pids/#{w.name}.pid" }

其中 /home/travis/.god/pids 是默认的 pids 目录

于 2011-03-28T09:32:08.503 回答
0

我在这里参加聚会可能有点晚了,但我们这边也有同样的问题。我们正在使用

rvm 2.1.0@ do bundle exec rake environment resque:work

这导致了多个进程。根据我们的系统操作员的说法,这是由于使用了rvm do,我们最终将其替换为

/path/to/rvm/gems/ruby-2.1.0/wrappers/bundle exec rake environment resque:work

这允许上帝按预期工作而无需指定 pid 文件。

于 2014-03-12T05:30:15.107 回答