2013-04-07 15 views
5

Im sử dụng Monit để giám sát một kịch bản ruby ​​có sử dụng Ruby daemons gem, mà ra mắt một quá trình riêng biệt với PID - theo các hướng dẫn từ Monitor ruby processes with MonitGiám sát của Ruby kịch bản, sử dụng Monit - Bao gồm RVM

Để thực thi kịch bản ruby ​​tôi cần để bao gồm RVM trong các chuỗi Monit startstop, vì vậy tôi có quyền truy cập tất cả các đá quý.

Tuy nhiên khi thực hiện .monitrc tôi nhận được lỗi sau:

$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 

tôi thêm PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm đến startstop chuỗi lệnh để thử và bao gồm RVM. Tuy nhiên vẫn còn nó không hoạt động

Config tập tin .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'" 

    .... 

Nhờ sự giúp đỡ của bạn.

EDIT

Tôi có cảm giác vấn đề liên quan đến biến môi trường. Trích dẫn từ 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'"

Trả lời

3

Sử dụng này:

/path/to/rvm/bin/rvm in /path/to/project do ... 

Thay thế những con đường với thư mục thích hợp cho RVM và dự án và ... với các lệnh để dừng/khởi động - thử:

/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" 

Lệnh này sẽ tải RVM, cd vào đường dẫn dự án, nạp ruby ​​cho ruby ​​này và thực thi lệnh đã cho.

+0

Tôi đã thử điều này: 'start =" /home/william/.rvm/bin/rvm trong/home/william/ruby ​​/ project do ruby ​​daemonloader.rb bắt đầu "'. Thật không may bây giờ tôi nhận được thông báo lỗi "Không thể tìm thấy cài đặt rvm!" và nó không thành công. 'Xxxx trong yyy do zzz' làm gì? Bạn có thể giải thích câu trả lời một chút không? Cảm ơn. – Imme22009

+0

bạn có đang chạy với tư cách là người dùng 'william' không? – mpapis

+0

Có - Người dùng: william. – Imme22009

0

Bạn có thể thử một cái gì đó như thế này trong Monit.

start = "/bin/su - william -c 'cd /home/william/ruby/project && ~/.rvm/bin/rvm default do bundle exec ruby daemonloader.rb start'" 

Điều này phù hợp với tôi.

Các vấn đề liên quan