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 start
và stop
, 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 start
và stop
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'"
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
bạn có đang chạy với tư cách là người dùng 'william' không? – mpapis
Có - Người dùng: william. – Imme22009