我试图用上帝监视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 #<God::Conditions::ProcessRunning:0x000000020929d0> 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 #<God::Conditions::ProcessRunning:0x000000020929d0> 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 #<God::Conditions::ProcessRunning:0x000000020929d0> 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”显示的相同吗?
答案 0 :(得分:8)
我不熟悉上帝(ehehe),但我怀疑它希望Redis不会守护自己(就像daemontools那样)。如果是这种情况,您应该在redis配置文件中打开自我守护程序。 IIRC是“daemonize = yes”参数,将其更改为no。这可能对你有用。
现在,如果是这种情况,PID文件可能不同的原因是上帝可能正在启动它并记录PID,然后当redis-server命令返回时,认为Redis已经死亡并尝试重新启动。此时它将记录一个新的PID。如果正在运行的PID小于文件中的PID,则很明显。