59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/propro/cli.rb', line 59
def deploy(script_path)
require 'net/ssh'
require 'net/scp'
require 'io/console'
puts Propro.color_banner
puts
script = Script.load(script_path)
address = (options[:server] || script.get_server)
password = (options[:password] || script.get_password || ask_password)
user = (options[:user] || script.get_user)
remote_home = (user == 'root' ? '/root' : "/home/#{user}")
remote_log_path = "#{remote_home}/provision.log"
remote_script_path = "#{remote_home}/provision.sh"
remote_script_url = address + remote_script_path
say_event 'build', script_path
script_data = StringIO.new(script.to_bash)
raise ArgumentError, 'no server address has been provided' if !address
raise ArgumentError, 'no server password has been provided' if !password
say_event 'connect', "#{user}@#{address}"
Net::SSH.start(address, user, password: password) do |session|
say_event 'upload', "#{script_path} -> #{remote_script_url}"
session.scp.upload!(script_data, remote_script_path)
session.exec!("chmod +x #{remote_script_path}")
session.exec!("touch #{remote_log_path}")
tail = session.exec("tail -f #{remote_log_path}") do |ch, stream, data|
STDOUT.write(data)
STDOUT.flush
end
sleep 1 say_event 'run', remote_script_url
puts
session.exec(remote_script_path) do |ch|
ch.on_data { } end
end
rescue IOError say_event 'done', "#{address} is rebooting"
end
|