我用上帝来观察我所有的东西(独角兽、redis、resque workers)。基本设置是这样的:
God 全局安装,在系统启动时加载并读取其配置文件/etc/god/all.god。
/etc/god/all.god
files = Dir.glob "/etc/god/**/*.god"
files.each do |f|
next if f == '/etc/god/all.god'
God.load f
end
此文件加载/etc/god 及其子项中的所有配置文件。部署脚本将配置文件放在那里并告诉上帝(重新)加载它们。
$ ls -l /etc/god
total 16
-rw-r--r-- 1 root root 108 2012-02-23 16:26 all.god
drwxr-xr-x 2 sergio sergio 4096 2012-03-20 20:59 app1_production
drwxr-xr-x 2 sergio sergio 4096 2012-03-27 00:58 app2_production
drwxr-xr-x 2 root root 4096 2012-04-23 01:37 util
$ ls -l /etc/god/app1_production/
total 0
lrwxrwxrwx 1 sergio sergio 55 2012-03-20 20:59 redis.god -> /srv/app1_production/current/config/god/redis.god
lrwxrwxrwx 1 sergio sergio 56 2012-03-20 20:59 resque.god -> /srv/app1_production/current/config/god/resque.god
lrwxrwxrwx 1 sergio sergio 57 2012-03-20 20:59 unicorn.god -> /srv/app1_production/current/config/god/unicorn.god
这是unicorn.god的负责人。
rails_env = "production"
pid_dir = "/srv/app1_#{rails_env}/shared/pids"
rails_root = "/srv/app1_#{rails_env}/current"
God.watch do |w|
w.name = "unicorn-#{rails_env}"
w.interval = 30.seconds # default
# unicorn needs to be run from the rails root
w.start = "cd #{rails_root} && /home/sergio/.rvm/bin/r193_bundle exec unicorn_rails -c #{rails_root}/config/unicorn/unicorn.#{rails_env}.rb -E #{rails_env} -D"
# QUIT gracefully shuts down workers
w.stop = "kill -QUIT `cat #{pid_dir}/unicorn.pid`"
# USR2 causes the master to re-create itself and spawn a new worker pool
w.restart = "kill -USR2 `cat #{pid_dir}/unicorn.pid`"
如您所见,unicorns 是通过 rvm 包装器启动的,因此每个新应用程序都可以使用自己的 ruby。另外,您提供自己的start、stop 和restart 命令,这样您就可以使用上帝来观看任何软件。
这种方法对我来说非常有效(到目前为止)。