Back

god进阶: 配置文件( god advanced: config file)

发布时间: 2014-01-14 00:20:00

参考(refer to )http://godrb.com/

每一个watch都代表一个process. 如果你有多个watch(process), 需要为每个process 分别指定pid_file. (If the process you're watching runs as a daemon (as mine does), you'll need to set the pid_file attribute.)

如果没有提供restart , 那么god会很聪明的先stop, 再执行start (god is smart enought to 'restart' by calling 'stop', 'start' if 'restart' command is not provided. )

可以以daemon 形式启动的process: (config files for those process that could be start as daemon )

# 注意: 对于可以以 daemon 形式执行的命令,用这个格式(注意其中的 restart, pid_file )   
God.watch do |w|
  w.name = "gravatar2-mongrel-#{port}"

  w.start = "mongrel_rails start -c #{RAILS_ROOT} -p #{port} \
    -P #{RAILS_ROOT}/log/mongrel.#{port}.pid  -d"
  w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"
  w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.#{port}.pid"

  w.pid_file = File.join(RAILS_ROOT, "log/mongrel.#{port}.pid")

  # 这个是内置的命令,在启动之前,清理残存的PID文件 
  w.behavior(:clean_pid_file)  
  ...
end

注意:对于 无法以 daemon 形式执行的process(只能以 nohup .. .& 的形式启动), 要用这样的配置文件: ( we should use this config file if the process could not be run as daemon except using "nohup...&")

# 注意: 不要有 stop, pid_file 以及 behavior 这三个东东。   
# (NOTICE: don't use stop, pid_file and behavior ) 
RAILS_ROOT = '/sg552/workspace/m-video-fetcher'
PID_FILE = RAILS_ROOT + '/tmp/pids/fetcher.pid'
COMMAND = "cd #{RAILS_ROOT} && ruby script/start_fetch.rb"
puts COMMAND
God.watch do |w| 
  w.name = 'fetcher'
  w.dir = RAILS_ROOT
  w.start = "ruby script/start_fetch.rb"
#  w.stop = "kill -9 $(cat #{PID_FILE})"
#  w.pid_file = PID_FILE
#  w.behavior :clean_pid_file
  w.log = "#{RAILS_ROOT}/fetcher.log"
  w.keepalive
end

Back