From 188231bc75652b35c33b49c0d8b8471295f61ecc Mon Sep 17 00:00:00 2001 From: junyi Date: Fri, 4 Sep 2026 11:55:04 +0000 Subject: [PATCH] Fix cross-host write error and closing "}" truncation bug. --- lib/tasks/change_site_server_name.rake | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/tasks/change_site_server_name.rake b/lib/tasks/change_site_server_name.rake index 4d756fb..7bc1808 100644 --- a/lib/tasks/change_site_server_name.rake +++ b/lib/tasks/change_site_server_name.rake @@ -33,24 +33,36 @@ namespace :create_site do nginx_file_content = site_construct.generate_nginx_text(raw_content) auto_update_infos("Writing via safe stream...") ssh.open_channel do |channel| - channel.exec("sudo -S sh -c 'cat > #{site_construct.nginx_file}'") do |ch, success| + channel.exec("sudo -S sh -c 'cat > #{site_construct.nginx_file}'") do |ch, success| + content_sent = false + send_content_once = lambda do + unless content_sent + content_sent = true + ch.send_data(nginx_file_content) + ch.eof! + end + end ch.on_extended_data do |c, type, data| if data =~ /password/i c.send_data("#{@password}\n") end + send_content_once.call end - ch.send_data(nginx_file_content) - ch.eof! + Thread.new { + sleep 2 + send_content_once.call + } end end ssh.loop exec_ssh_command_by_sudo(ssh, "service nginx restart") auto_update_infos("Finish!") - end + end def exec_command_by_user(session,command) output = session.exec!(command) - return output[0...-1].gsub(/^\n[\n]+/,'') + output = output[0...-1] if output.end_with?("\n") + return output.gsub(/^\n[\n]+/,'') end def exec_ssh_command_by_sudo(session,command) output = session.exec!("echo '#{@password}' | sudo -S #{command}")