我正在使用God(一个Ruby gem)监控我的redis服务器。然而,我现有的服务器可能已经有一个redis实例。我怎么能确保它监控现有的Redis服务器进程已经启动?
这是我的God file for redis:
rails_root = ENV['RAILS_ROOT']
redis_root = "/usr/local/bin"
# Redis
%w{6379}.each do |port|
God.watch do |w|
w.name = "redis"
w.interval = 30.seconds
w.start = "#{redis_root}/redis-server /etc/redis/redis.conf"
w.stop = "#{redis_root}/redis-cli shutdown"
w.restart = "#{w.stop} && #{w.start}"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.log = File.join(rails_root, 'log', 'redis.log')
w.keepalive(:memory_max => 5000.megabytes)
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
end
end
回答这个问题:
我放了一个w.pid_file = "SOMETHING"在我的God文件中,并确保这个PID文件也设置在Redis的配置文件中。
您还应该添加:
w.pid_file = "Your_pid_file_name"
,然后用
清理pid文件w.behaviour(:clean_pid_file)