ruby-on-rails 使用Monit on RBenv设置管理Resque worker

pu82cl6c  于 2023-05-02  发布在  Ruby
关注(0)|答案(4)|浏览(129)

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

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
nbnkbykc

nbnkbykc1#

我不确定这是否有帮助,但是在我的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"
pvcm50d1

pvcm50d12#

我看到这个主题是在2012年创建的,但我也遇到了类似的问题,这个主题在谷歌上排名第一。
问题是monit使用受限的env启动命令(env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh来模拟)。
要在rbenv中使用monit,必须在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
hl0ma9xz

hl0ma9xz3#

这对我很有效。
检查进程app_resque_worker与pidfile〈%= 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 %〉;bundle exec rake environment resque:work RAILS_ENV=production BACKGROUND=yes QUEUE=* PIDFILE=〈%= resque_pid %〉'"
停止程序=“kill -9 cat <%= resque_pid%> && rm -f〈%= resque_pid%〉”
如果totalmem在10个周期内大于2000 MB,则重新启动

1szpjjfi

1szpjjfi4#

是的,我不确定这是否有帮助,但是在我的monitrc启动行中,我必须首先su到我想要运行的用户。我还没有尝试使用uid和gid标志来了解它是否有效

相关问题