2012-11-17 31 views
6

我正在嘗試爲Sidekiq設置Monit。這裏是我到目前爲止我的配置文件:Monit Ruby on Rails Sidekiq

check process sidekiq_site 
    with pidfile /var/www/site/tmp/pids/sidekiq.pid 
    start program = "bundle exec sidekiq -C /var/www/site/config/sidekiq.yml -P /var/www/site/tmp/pids/sidekiq.pid" with timeout 90 seconds 
    if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory? 
    group site_sidekiq 

的問題是我得到的消息,當我運行的monit重新加載程序「捆綁」不存在。

有沒有人有解決方案?

+2

儘量寫全路徑打捆,像'/usr/local/lib/ruby/gems/1.9/ gem/bundler-1.2.3/bin/bundle「,甚至在路徑前加上ruby路徑。使用命令'哪個包'來查找完整路徑。 – taro

回答

1

這是一個要點我在GitHub上寫道:

check process sidekiq_production with pidfile /var/run/sidekiq_production.pid 
     depends on redis-server 
     start program = "/etc/init.d/sidekiq_production start" with timeout 90 seconds 
     stop program = "/etc/init.d/sidekiq_production stop" with timeout 90 seconds 
     if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory? 
     if 2 restarts within 3 cycles then timeout 

我也寫了一個init腳本sidekiq在Debian:https://gist.github.com/alain75007/5517948

4

上工作後,我自己的monit和sidekiq配置,我可以分享運行ubuntu的工作。

首先,如果你使用的是發行版,那麼ubuntu會有一個sidekiq upstart腳本。有用於sidekiq和管理工作人員的腳本:https://github.com/mperham/sidekiq/tree/master/examples/upstart/manage-one

我遇到了一些錯誤與默認暴發戶腳本,因爲我使用rvm。檢查/var/logs/upstart/sidekiq-0.log可以發現一些問題。 這條線:

exec bin/sidekiq -i ${index} -e production -C config/sidekiq.yml -P tmp/pids/sidekiq-${index}.pid

需要改爲exec bundle exec sidekiq +選項

然後,對於符合我RVM藏在心裏安裝,我改變了以下內容:

#source $HOME/.rvm/scripts/rvm 
source /usr/local/rvm/scripts/rvm 

在/ etc/monit/monitrc中我引用了新貴腳本並且有:

# sidekiq 
check process sidekiq 
    with pidfile /var/www/apps/myapp/current/tmp/pids/sidekiq-0.pid 
    start program = "/usr/bin/sudo start sidekiq index=0" 
    stop program = "/usr/bin/sudo stop sidekiq index=0" 
    if totalmem is greater than 500 MB for 2 cycles then restart # eating up memory? 
    if 3 restarts within 5 cycles then timeout 
0

您的問題是缺少命令包。 我覺得你應該寫這樣的monit的配置文件:

check process sidekiq 
    with pidfile /srv/www/projects/myapp/shared/log/production.sidekiq.pid 
    start program = "/usr/bin/env /usr/bin/env HOME=/home/USER_NAME RACK_ENV=production RAILS_ENV=production PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd /srv/www/rails/myapp/current; bundle exec sidekiq'" as uid USER_NAME 
    stop program = "/usr/bin/env /usr/bin/env HOME=/home/USER_NAME RACK_ENV=production RAILS_ENV=production PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd/
    group myapp_workers 

如果你走進的應用程序目錄中並捆綁,我認爲它的工作。

0

下面是與RVM

check process sidekiq-th with pidfile /web/vcms/tmp/pids/sidekiq.pid 
    start program = "/home/dimon/.rvm/bin/rvm-shell -c '/web/vcms/sidekiq.sh start'" 
    stop program = "/bin/bash /web/vcms/sidekiq.sh stop &" 

它採用了script在Ubuntu工程的配置,主要線路是

開始

cd /web/vcms; sidekiq -d -e production & 

,並停止

sidekiqctl stop $PIDFILE 

我不是一個shell腳本大師和將感謝任何意見=)

1

最後這個解決方案爲我般的魅力:)

check process sidekiq with pidfile path_to_my_pid_file/sidekiq.pid 

start program = "/bin/bash -c 'cd my_app_current && source /home/myuser/.rvm/environments/[email protected] && bundle exec sidekiq -e production -P path_to_my_pid_file/sidekiq.pid -L /my_shared_folder_path/log/sidekiq.log -C my_app_current/config/sidekiq.yml --daemon'" as uid "myuser" and gid "myuser" 

stop program = "/bin/bash -c 'kill -s INT `cat path_to_my_pid_file/sidekiq.pid`'" as uid "myuser" and gid "myuser" 

**請注意以下幾點幾點:**

  • 我使用RVM紅寶石版本管理請rbenv檢查。
  • 在這裏,你需要通過紅寶石的全局位置的方式,我通過在這裏: - /home/myuser/.rvm/environments/[email protected]