加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用Monit监控Ruby脚本 – 包括RVM

发布时间:2020-12-16 20:58:02 所属栏目:百科 来源:网络整理
导读:我使用Monit监视使用 Ruby daemons gem的ruby脚本,它使用PID启动一个单独的进程 – 按照 Monitor ruby processes with Monit的说明进行操作 为了执行ruby脚本,我需要在Monit的开始和停止字符串中包含RVM,这样我就可以访问所有的gem. 但是当.monitrc执行时,我
我使用Monit监视使用 Ruby daemons gem的ruby脚本,它使用PID启动一个单独的进程 – 按照 Monitor ruby processes with Monit的说明进行操作

为了执行ruby脚本,我需要在Monit的开始和停止字符串中包含RVM,这样我就可以访问所有的gem.

但是当.monitrc执行时,我收到以下错误:

$rvm_path (/usr/local/rvm) does not exist./home/william/.rvm/scripts/rvm: line 174: rvm_is_a_shell_function: command not found
/home/william/.rvm/scripts/rvm: line 185: __rvm_teardown: command not found
'myserver_1' failed to start
Aborting event

我添加了PATH = $PATH:/home/william/.rvm/bin&& . /home/william/.rvm/scripts/rvm启动和停止命令字符串以尝试包含RVM.但是它仍然无效

配置文件.monitrc:

....

check process myserver_1
  with pidfile /home/william/ruby/barclays/myapp.rb.pid
  start = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb start'"
  stop = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb stop'"

  ....

谢谢你的帮助.

编辑

我感觉问题与环境变量有关.引自this page

You should also know that for security reasons Monit purges the
environment and only sets a spartan PATH variable that contains /bin,
/usr/bin,/sbin and /usr/sbin. If your program or script dies,the
reason could be that it expects certain environment variables or to
find certain programs via PATH. If this is the case you should set the
environment variables you need directly in the start or stop script
called by monit.

Finally,Monit uses the system call execv to execute a program or a
script. This means that you cannot write shell commands directly in
the start,stop or exec statements. To do this,you must do as above;
start a shell and issue your commands there. For example:

start program = “/bin/bash -c ‘my shell command && my other
command'”

解决方法

用这个:
/path/to/rvm/bin/rvm in /path/to/project do ...

用rvm和project的正确目录替换路径,用命令停止/启动… – 尝试:

/usr/bin/env "HOME=/home/william rvm_path=/home/william/.rvm 
  /home/william/.rvm/bin/rvm in /home/william/ruby/project do
  ruby daemonloader.rb start"

此命令将加载RVM,cd到项目路径,为此ruby加载ruby并执行给定命令.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读