在RBenv设置上使用Monit管理Resque工作者

时间:2012-08-23 14:45:51

标签: ruby-on-rails resque monit rbenv

我正在尝试设置Monit来管理Resque工作者,但它没有开始说/home/deployer/.rbenv/shims/bundle: line 4: exec: rbenv: not found 我已经检查过它是以deployer用户身份运行命令,如果我直接通过SSH复制并粘贴命令,一切正常。下面是我的Monit配置。谢谢!

check process resque_worker_1
  with pidfile CURRENT_PATH/tmp/pids/resque_worker_1.pid
  start program = "/usr/bin/env HOME=/home/deployer RACK_ENV=production PATH=/home/deployer/.rbenv/shims:/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd CURRENT_PATH; bundle exec rake environment resque:work RAILS_ENV=production QUEUE=high,normal,low VERBOSE=1 PIDFILE=CURRENT_PATH/tmp/pids/resque_worker_1.pid >> CURRENT_PATH/log/resque_worker_.log 2>&1'" 
    as uid deployer and gid admin
  stop program = "/bin/sh -c 'cd CURRENT_PATH && kill -9 $(cat tmp/pids/resque_worker_1.pid) && rm -f tmp/pids/resque_worker_1.pid; exit 0;'"
    as uid deployer and gid admin
  if totalmem is greater than 300 MB for 10 cycles then restart  # eating up memory?
  group resque_workers

3 个答案:

答案 0 :(得分:1)

我不确定这是否有帮助,但在我的monitrc起始行中,我必须先向我想要运行的用户su。我没有尝试使用uid和gid标志来知道它是否运行良好,所以这可能是一个回答的追逐。

我记得和你有同样的问题但是...一切都在命令行上运行,但是当monit会做它的时候不行。

例如,在我的monitrc中,我正在使用以下内容监视arsendmail:

# arsendmail_rails3
# daemon that watches and sends mail from the rails app
check process ar_sendmail with pidfile /var/www/rak/log/ar_sendmail.pid
start program "/bin/su - mike && /bin/bash -c 'cd /var/www/rak && ar_sendmail_rails3 -b1000 -d -e production'"
stop program "/bin/ps -ef | /bin/grep ar_sendmail_rails3 | /bin/grep -v grep | /usr/bin/awk '{ /usr/bin/print $2}' | /usr/bin/xargs /bin/kill -9"

答案 1 :(得分:1)

我看到该主题是在2012年创建的,但我遇到了类似的问题,这个帖子在谷歌排名第一。

问题是monit启动命令带有受限制的env(env -i PATH = / bin:/ usr / bin:/ sbin:/ usr / sbin / bin / sh来模拟)。

要将monit与rbenv一起使用,必须在bundle exec命令之前指定正确的路径。

PATH = / home / [USER] /。rbenv / bin:/ home / [USER] / .rbenv / shims:$ PATH bundle exec ...

独角兽的例子:

check process unicorn_dev with pidfile /home/wizville/app/dev.wizville.fr/shared/pids/unicorn.pid
  group dev
  start program =  "/bin/bash -c 'cd /home/wizville/app/dev.wizville.fr/current && PATH=/home/wizville/.rbenv/bin:/home/wizville/.rbenv/shims:$PATH bundle exec unicorn -c config/unicorn.rb -D'" as uid "wizville"
  stop program = "/bin/bash -c 'kill -s QUIT `cat /home/wizville/app/dev.wizville.fr/shared/pids/unicorn.pid`'"
  depends on mysql

答案 2 :(得分:0)

这对我有用。

使用pidfile检查进程app_resque_worker<%= resque_pid%>   start program =“/ usr / bin / env HOME = / home / subcaster RACK_ENV = production PATH = / home / subcaster / .rvm / rubies / ruby​​-2.0.0-p247 / bin / ruby​​:/ usr / local / bin: / usr / local / ruby​​ / bin:/ usr / bin:/ bin:$ PATH / bin / sh -l -c \'cd<%= current_path%&gt ;; bundle exec rake environment resque:work RAILS_ENV = production BACKGROUND =是QUEUE = * PIDFILE =<%= resque_pid%> \'“

停止program =“kill -9 cat <%= resque_pid%>&amp;&amp; rm -f&lt;%= resque_pid%&gt;”

如果totalmem在10个周期内大于2000 MB,则重新启动