2013-01-21 82 views
1

嗨我試圖使用ruby net/ssh gem(2.0.24)連接到遠程服務器並運行rake任務。我可以使用下面概述的腳本運行其他簡單的任務,但是rake失敗。ruby​​ net/ssh無法遠程執行rake命令

這是我的代碼

Net::SSH.start("myremote_server", 'ubuntu', :keys => ['abcdef.pem'], :paranoid => false, :verbose => :debug) do |ssh| 
    result = ssh.exec!("cd a_rails_directory; rake sunspot:solr:start") 
    puts result 
    ssh.loop 
end 

,我得到了以下錯誤消息

rake aborted! 
uninitialized constant Bundler 
/home/ubuntu/a_rails_directory/config/boot.rb:9:in `rescue in <top (required)>' 
/home/ubuntu/a_rails_directory/config/boot.rb:5:in `<top (required)>' 
/home/ubuntu/a_rails_directory/config/application.rb:1:in `<top (required)>' 
/home/ubuntu/a_rails_directory/Rakefile:4:in `<top (required)>' 
(See full trace by running task with --trace) 

當我ssh-到我可以很容易地運行rake TAKS遠程服務器手動,但它不適用於net/ssh,正如我上面所概述的那樣。

不知何故,我覺得我沒有連接適當的shell或正確訪問路徑變量,但我不知道,我也不知道如何解決它。 有什麼想法?

TIA

+0

嘗試在你的產品環境中執行'bundle exec rake ...'。 –

回答

2

沒關係。想出瞭如何加載相關的紅寶石路徑信息

result = ssh.exec!("[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\" ; cd rails_directory; rake sunspot:solr:start")