上帝是否有可能按顺序启动两个过程?
我正在使用依赖Redis的Sidekiq。我想启动Redis,然后启动Sidekiq,我有两个独立的手表设置,它们可以独立工作,但是当我运行时:
$ god -c "./config.god" -D
似乎上帝试图同时启动两者,导致Sidekiq出错,因为它无法连接到Redis服务器。
我的上帝配置文件如下:
# config.god
PROJECT_ROOT = ENV['PROJECT_ROOT'] || "/Path/to/app"
God.watch do |w|
w.name = "redis-server"
w.group = 'conversion-api'
w.interval = 30.seconds
w.start = "/usr/local/Cellar/redis/2.4.16/bin/redis-server"
end
God.watch do |w|
w.name = "sidekiq"
w.group = 'conversion-api'
w.interval = 20.seconds
w.dir = ENV['PROJECT_ROOT']
w.start = "bundle exec sidekiq -v -C #{PROJECT_ROOT}/config.yml -r #{PROJECT_ROOT}/app.rb -c 10"
w.stop = "bundle exec sidekiqctl stop #{PROJECT_ROOT}/tmp/pids/sidekiq.pid 5"
w.keepalive
# Don't pass in a pid file location. Let God handle things. Leaving a pid file location in
# the sidekiq config.yml seems to be harmless though and it lets us force stop sidekiq independently
# of God.
# w.pid_file = File.join(PROJECT_ROOT, 'tmp/pids/sidekiq.pid')
w.log = "./log/god_sidekiq.log"
w.behavior(:clean_pid_file)
end
答案 0 :(得分:0)
我也想知道控制启动顺序。我开始考虑在sidekiq监视对象上使用监视转换方法并检查redis进程是否正在运行的可能性:通过可能的God.watches [“redis”] .state ==:up然后启动sidekiq。时间过了,只是放了一个“睡5”的黑客。在sidekiq开始之前和redis关闭之前。