Fix cross-host write error and closing "}" truncation bug.

This commit is contained in:
junyi 2026-09-04 11:55:04 +00:00
parent f75bd8bbf0
commit 188231bc75
1 changed files with 17 additions and 5 deletions

View File

@ -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}")