2

我正在使用这个 gem 来部署kapify

这是我的独角兽配置:

独角兽配置

独角兽变种erb

unicorn_init.erb

我的部署中有:

server "111.111.111.111", :web, :app, :db, primary: true

set :application, 'myapp'
set :user, "hyperrjas"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "path_to_my_remote_reposytory.git"
set :branch, "master"
set :current_path, "/home/#{user}/apps/#{application}/current"
set :shared_path, "/home/#{user}/apps/#{application}/shared"

set :unicorn_workers, 1
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
set :server_name, "myserver.com"

这是我在远程服务器中的 pid:

ps aux | grep unicorn
1000      6037  0.4 12.5 320464 127628 ?       Sl   14:09   0:37 unicorn master -c /home/hyperrjas/apps/myapp/shared/config/unicorn.rb -D                                                         
1000      6079  0.2 13.8 335784 140828 ?       Sl   14:10   0:17 unicorn worker[0] -c /home/hyperrjas/apps/myapp/shared/config/unicorn.rb -D                                                      
1000      6322  0.0  0.0   9384   868 pts/0    S+   16:14   0:00 grep unicorn

这是我的config/deploy/templates/monit/unicorn.erb文件:

check process myapp_unicorn with pidfile /home/hyperrjas/apps/myapp/current/tmp/pids/unicorn.pid
start program = "/etc/init.d/unicorn_myapp start"
stop program = "/etc/init.d/unicorn_myapp force-stop"

check process myapp_unicorn_worker_0 with pidfile /home/hyperrjas/apps/myapp/current/tmp/pids/unicorn.0.pid
start program = "/bin/true"
stop program = "/usr/bin/test -s /home/hyperrjas/apps/myapp/current/tmp/pids/unicorn.0.pid && /bin/kill -QUIT `cat /home/hyperrjas/apps/myapp/current/tmp/pids/unicorn.0.pid`"
if mem > 200.0 MB for 5 cycles then restart
if cpu > 50% for 15 cycles then restart
if 5 restarts within 25 cycles then timeout
alert myapp@gmail.com only on { pid }
if changed pid 2 times within 64 cycles then alert

我可以在monit中看到unicorn worker pid的下一条路径:

Pid file /home/hyperrjas/apps/myapp/current/tmp/pids/unicorn.0.pid

和消息:

Status  Not monitored

远程服务器中的独角兽 pid 在/home/myapp/apps/myapp/current/tmp/pids/unicorn.pid

unicorn.0.pid我看不到pid/home/hyperrjas/apps/myapp/current/tmp/pids/

Monit 正在监视独角兽 pid。

我如何监控我的独角兽工人?

4

1 回答 1

1

我在设置 monit 时 使用了这个配置来观察我的 Linode 上三个不同应用程序的独角兽主进程和工作进程。本文将引导您完成设置以及每件事如何协同工作。

我不建议尝试即时为 unicorn 生成 monit 配置,而是告诉 unicorn 始终将 PID 写入您的应用程序中的相同文件名,然后在 monit 配置中引用这些文件。

如果您遇到困难,请告诉我,我会帮助您。另外,如果我的配置有帮助,请告诉我,我会发布。

于 2013-05-02T22:59:10.597 回答