当前位置:  开发笔记 > 编程语言 > 正文

监控redis与神 - 监控条件

如何解决《监控redis与神-监控条件》经验,为你挑选了1个好方法。

我试图用上帝监视redis但是上帝试图重新启动它,即使它已经在运行.这是我的.god脚本(移植自http://blog.thomasmango.com/post/636319317/resque-in-production):

# Redis
%w{6379}.each do |port|
  God.watch do |w|
    w.name = "redis-server"
    w.interval = 30.seconds
    w.start = "/etc/init.d/redis-server start"
    w.stop = "/etc/init.d/redis-server stop"
    w.restart = "/etc/init.d/redis-server restart"
    w.start_grace = 10.seconds
    w.restart_grace = 10.seconds

    w.start_if do |start|
      start.condition(:process_running) do |c|
          c.interval = 5.seconds
          c.running = false
      end
    end
  end
end

现在当我像这样开始上帝:

god -c /home/phlegx/workspace/projectx/config/god/config.god -D --log-level debug

我得到以下输出:

I [2011-04-28 18:32:10]  INFO: Loading /home/phlegx/workspace/projectx/config/god/config.god
I [2011-04-28 18:32:10]  INFO: Syslog enabled.
I [2011-04-28 18:32:10]  INFO: Using pid file directory: /var/run/god
I [2011-04-28 18:32:10]  INFO: Started on drbunix:///tmp/god.17165.sock
I [2011-04-28 18:32:10]  INFO: redis-server move 'unmonitored' to 'up'
D [2011-04-28 18:32:10] DEBUG: driver schedule # in 0 seconds
I [2011-04-28 18:32:10]  INFO: redis-server moved 'unmonitored' to 'up'
I [2011-04-28 18:32:10]  INFO: redis-server [trigger] process is not running (ProcessRunning)
D [2011-04-28 18:32:10] DEBUG: redis-server ProcessRunning [true] {true=>:start}
I [2011-04-28 18:32:10]  INFO: redis-server move 'up' to 'start'
I [2011-04-28 18:32:10]  INFO: redis-server start: /etc/init.d/redis-server start
D [2011-04-28 18:32:20] DEBUG: driver schedule # in 0 seconds
I [2011-04-28 18:32:20]  INFO: redis-server moved 'up' to 'up'
I [2011-04-28 18:32:20]  INFO: redis-server [trigger] process is not running (ProcessRunning)
D [2011-04-28 18:32:20] DEBUG: redis-server ProcessRunning [true] {true=>:start}
I [2011-04-28 18:32:20]  INFO: redis-server move 'up' to 'start'
I [2011-04-28 18:32:20]  INFO: redis-server start: /etc/init.d/redis-server start

D [2011-04-28 18:32:30] DEBUG: driver schedule # in 0 seconds
I [2011-04-28 18:32:30]  INFO: redis-server moved 'up' to 'up'
I [2011-04-28 18:32:30]  INF (ProcessRunning)O: redis-server [trigger] process is not running
D [2011-04-28 18:32:30] DEBUG: redis-server ProcessRunning [true] {true=>:start}
I [2011-04-28 18:32:30]  INFO: redis-server move 'up' to 'start'
I [2011-04-28 18:32:30]  INFO: redis-server start: /etc/init.d/redis-server start

你可以看到它总是抱怨:

INF (ProcessRunning)O: redis-server [trigger] process is not running

有谁知道这可能导致什么?

上帝写给"/var/run/god/redis-server.pid"的PID似乎与我执行"ps"时不一样:

ps aux | grep redis
redis     7702  0.0  0.0   9876  1376 ?        Ss   18:00   0:01 /usr/bin/redis-server /etc/redis/redis.conf

"redis-server.pid"中的PID不应与"ps"显示的相同吗?



1> The Real Bil..:

我不熟悉上帝(ehehe),但我怀疑它希望Redis不会守护自己(正如daemontools那样).如果是这种情况,您应该在redis配置文件中打开自我守护程序.IIRC是"daemonize = yes"参数,将其更改为no.这可能对你有用.

现在,如果是这种情况,PID文件可能不同的原因是上帝可能正在启动它并记录PID,然后当redis-server命令返回时它认为Redis已经死亡并尝试重新启动.此时它将记录一个新的PID.如果正在运行的PID小于文件中的PID,则这很明显.

推荐阅读
跟我搞对象吧
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有