工作我有一個Rails應用程序,用戶可以在提交表單,它熄滅,通過ssh連接到遠程服務器調用的腳本。最終我打算使用delayed_job或類似的東西,但即使是一個簡單的測試,我也無法讓它在生產環境中工作。的Net :: SSH從生產軌道控制檯,AuthenticationFailed從生產的webapp
奇怪的是,淨:: SSH工作得很好,從生產中的控制檯,但它失敗AuthenticationFailed當我在生產中提交表單。控制檯和webapp在開發過程中都可以正常工作。
錯誤:
Net::SSH::AuthenticationFailed (my_ssh_username):
app/models/branch.rb:69:in `ssh_to_machine'
app/controllers/branches_controller.rb:55:in `update'
控制器的更新動作:
def update
@branch = Branch.find(params[:id])
if @branch.update_attributes(params[:branch])
@branch.ssh_to_machine(@branch.hostname, @branch.user_name, @branch.command_to_run)
redirect_to @branch, :notice => "Update request now processing."
else
render :action => 'edit'
end
end
方法我打電話,主要是複製/從網上粘貼:: SSH API例如:
def ssh_to_machine(host_name, user_name, command_to_run)
require 'net/ssh'
Net::SSH.start(host_name, user_name, { :verbose => Logger::DEBUG, :keys => %w{ /home/www-data/.ssh/my_ssh_username_id_rsa }, :auth_methods => %w{ publickey } }) do |ssh|
# capture all stderr and stdout output from a remote process
output = ssh.exec!("hostname")
# run multiple processes in parallel to completion
ssh.exec command_to_run
ssh.loop
end
end
我已經嘗試過,沒有:verbose,:keys,:auth_methods;每次都要小心地重新啓動apache,但在生產過程中,它總是從控制檯運行(RAILS_ENV =在調用'rails c'之前導出的生產),並且從不從webapp運行。
我也歡迎就如何獲得增強記錄任何建議時,我從web應用程序調用它 - :在控制檯上冗長的工作對我來說卻沒有我的production.log添加任何東西。
當你用'rails c production'啓動控制檯時它工作嗎? – rdvdijk
是的,謝謝@rdvdijk,我只是試過'rails c production',它工作正常。 – wonderfulthunk
只是爲了澄清,「rails c production」和SSH在生產控制檯上工作正常,但它仍然從生產webapp失敗。 – wonderfulthunk