工作我有一个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