engineyard-serverside 1.5.35.pre.2 → 1.6.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/engineyard-serverside.rb +3 -1
- data/lib/engineyard-serverside/cli.rb +73 -38
- data/lib/engineyard-serverside/configuration.rb +38 -12
- data/lib/engineyard-serverside/deploy.rb +63 -51
- data/lib/engineyard-serverside/deploy_hook.rb +21 -18
- data/lib/engineyard-serverside/deprecation.rb +9 -17
- data/lib/engineyard-serverside/lockfile_parser.rb +1 -1
- data/lib/engineyard-serverside/rails_asset_support.rb +5 -5
- data/lib/engineyard-serverside/server.rb +8 -11
- data/lib/engineyard-serverside/shell.rb +101 -0
- data/lib/engineyard-serverside/shell/formatter.rb +70 -0
- data/lib/engineyard-serverside/shell/helpers.rb +29 -0
- data/lib/engineyard-serverside/strategies/git.rb +12 -15
- data/lib/engineyard-serverside/task.rb +28 -5
- data/lib/engineyard-serverside/version.rb +1 -1
- data/lib/vendor/open4/lib/open4.rb +432 -0
- data/spec/basic_deploy_spec.rb +9 -9
- data/spec/bundler_deploy_spec.rb +1 -1
- data/spec/custom_deploy_spec.rb +45 -4
- data/spec/deploy_hook_spec.rb +77 -78
- data/spec/deprecation_spec.rb +4 -26
- data/spec/git_strategy_spec.rb +6 -2
- data/spec/nodejs_deploy_spec.rb +2 -2
- data/spec/services_deploy_spec.rb +11 -10
- data/spec/shell_spec.rb +48 -0
- data/spec/spec_helper.rb +48 -25
- data/spec/sqlite3_deploy_spec.rb +1 -2
- data/spec/support/integration.rb +1 -13
- metadata +57 -97
- data/lib/engineyard-serverside/logged_output.rb +0 -91
- data/lib/vendor/systemu/LICENSE +0 -3
- data/lib/vendor/systemu/lib/systemu.rb +0 -363
- data/lib/vendor/systemu/systemu.gemspec +0 -45
- data/spec/fixtures/gitrepo/bar +0 -0
- data/spec/logged_output_spec.rb +0 -55
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'systemu'
|
2
|
-
|
3
|
-
module EY
|
4
|
-
module Serverside
|
5
|
-
module LoggedOutput
|
6
|
-
|
7
|
-
class Tee
|
8
|
-
def initialize(*streams)
|
9
|
-
@streams = streams.flatten
|
10
|
-
end
|
11
|
-
|
12
|
-
def <<(output)
|
13
|
-
@streams.each do |s|
|
14
|
-
s << output
|
15
|
-
s.flush
|
16
|
-
end
|
17
|
-
self
|
18
|
-
end
|
19
|
-
end # Tee
|
20
|
-
|
21
|
-
@@logfile = File.join(ENV['HOME'], 'ey.log')
|
22
|
-
def self.logfile=(filename)
|
23
|
-
File.unlink filename if File.exist?(filename) # start fresh
|
24
|
-
@@logfile = filename
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.logfile
|
28
|
-
@@logfile
|
29
|
-
end
|
30
|
-
|
31
|
-
@@verbose = false
|
32
|
-
def self.verbose=(v)
|
33
|
-
@@verbose = !!v
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.verbose?
|
37
|
-
@@verbose
|
38
|
-
end
|
39
|
-
|
40
|
-
def verbose?
|
41
|
-
EY::Serverside::LoggedOutput.verbose?
|
42
|
-
end
|
43
|
-
|
44
|
-
def warning(msg)
|
45
|
-
info "WARNING: #{msg}\n".gsub(/^/,'!> ')
|
46
|
-
end
|
47
|
-
|
48
|
-
def info(msg)
|
49
|
-
with_logfile do |log|
|
50
|
-
Tee.new($stdout, log) << ("#{with_timestamp(msg)}\n")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def debug(msg)
|
55
|
-
with_logfile do |log|
|
56
|
-
log << "#{with_timestamp(msg)}\n"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def logged_system(cmd)
|
61
|
-
with_logfile do |log|
|
62
|
-
out = verbose? ? Tee.new($stdout, log) : log
|
63
|
-
err = Tee.new($stderr, log) # we always want to see errors
|
64
|
-
|
65
|
-
cmd = "sh -c #{Escape.shell_command([cmd])}"
|
66
|
-
puts "running #{cmd}" if ENV['DEBUG']
|
67
|
-
out << with_timestamp(":: running #{cmd}\n")
|
68
|
-
status = systemu cmd, 'stdout' => out, 'stderr' => err
|
69
|
-
puts "exit status= #{status.exitstatus}" if ENV['DEBUG']
|
70
|
-
status.exitstatus == 0
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
def with_logfile
|
76
|
-
File.open(logfile, 'a') {|f| yield f }
|
77
|
-
end
|
78
|
-
|
79
|
-
def logfile
|
80
|
-
EY::Serverside::LoggedOutput.logfile
|
81
|
-
end
|
82
|
-
|
83
|
-
def with_timestamp(msg)
|
84
|
-
return msg unless respond_to?(:starting_time)
|
85
|
-
time_passed = Time.now.to_i - starting_time.to_i
|
86
|
-
timestamp = "+%2dm %02ds " % time_passed.divmod(60)
|
87
|
-
msg.gsub(/^/, timestamp)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/lib/vendor/systemu/LICENSE
DELETED
@@ -1,363 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'tmpdir'
|
4
|
-
require 'socket'
|
5
|
-
require 'fileutils'
|
6
|
-
require 'rbconfig'
|
7
|
-
require 'thread'
|
8
|
-
|
9
|
-
class Object
|
10
|
-
def systemu(*a, &b) SystemUniversal.new(*a, &b).systemu end
|
11
|
-
end
|
12
|
-
|
13
|
-
class SystemUniversal
|
14
|
-
#
|
15
|
-
# constants
|
16
|
-
#
|
17
|
-
SystemUniversal::VERSION = '2.5.0' unless SystemUniversal.send(:const_defined?, :VERSION)
|
18
|
-
def SystemUniversal.version() SystemUniversal::VERSION end
|
19
|
-
def version() SystemUniversal::VERSION end
|
20
|
-
#
|
21
|
-
# class methods
|
22
|
-
#
|
23
|
-
|
24
|
-
@host = Socket.gethostname
|
25
|
-
@ppid = Process.ppid
|
26
|
-
@pid = Process.pid
|
27
|
-
@turd = ENV['SYSTEMU_TURD']
|
28
|
-
|
29
|
-
c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
|
30
|
-
ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
|
31
|
-
@ruby = if system('%s -e 42' % ruby)
|
32
|
-
ruby
|
33
|
-
else
|
34
|
-
system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
|
35
|
-
end
|
36
|
-
|
37
|
-
class << SystemUniversal
|
38
|
-
%w( host ppid pid ruby turd ).each{|a| attr_accessor a}
|
39
|
-
|
40
|
-
def quote(*words)
|
41
|
-
words.map{|word| word.inspect}.join(' ')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# instance methods
|
47
|
-
#
|
48
|
-
|
49
|
-
def initialize argv, opts = {}, &block
|
50
|
-
getopt = getopts opts
|
51
|
-
|
52
|
-
@argv = argv
|
53
|
-
@block = block
|
54
|
-
|
55
|
-
@stdin = getopt[ ['stdin', 'in', '0', 0] ]
|
56
|
-
@stdout = getopt[ ['stdout', 'out', '1', 1] ]
|
57
|
-
@stderr = getopt[ ['stderr', 'err', '2', 2] ]
|
58
|
-
@env = getopt[ 'env' ]
|
59
|
-
@cwd = getopt[ 'cwd' ]
|
60
|
-
|
61
|
-
@host = getopt[ 'host', self.class.host ]
|
62
|
-
@ppid = getopt[ 'ppid', self.class.ppid ]
|
63
|
-
@pid = getopt[ 'pid', self.class.pid ]
|
64
|
-
@ruby = getopt[ 'ruby', self.class.ruby ]
|
65
|
-
end
|
66
|
-
|
67
|
-
def systemu
|
68
|
-
tmpdir do |tmp|
|
69
|
-
c = child_setup tmp
|
70
|
-
status = nil
|
71
|
-
|
72
|
-
begin
|
73
|
-
thread = nil
|
74
|
-
|
75
|
-
quietly{
|
76
|
-
IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'r+' do |pipe|
|
77
|
-
line = pipe.gets
|
78
|
-
case line
|
79
|
-
when %r/^pid: \d+$/
|
80
|
-
cid = Integer line[%r/\d+/]
|
81
|
-
else
|
82
|
-
begin
|
83
|
-
buf = pipe.read
|
84
|
-
buf = "#{ line }#{ buf }"
|
85
|
-
e = Marshal.load buf
|
86
|
-
raise unless Exception === e
|
87
|
-
raise e
|
88
|
-
rescue
|
89
|
-
raise "wtf?\n#{ buf }\n"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
thread = new_thread cid, @block if @block
|
93
|
-
pipe.read rescue nil
|
94
|
-
end
|
95
|
-
}
|
96
|
-
status = $?
|
97
|
-
ensure
|
98
|
-
if thread
|
99
|
-
begin
|
100
|
-
class << status
|
101
|
-
attr 'thread'
|
102
|
-
end
|
103
|
-
status.instance_eval{ @thread = thread }
|
104
|
-
rescue
|
105
|
-
42
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if @stdout or @stderr
|
111
|
-
open(c['stdout']){|f| relay f => @stdout} if @stdout
|
112
|
-
open(c['stderr']){|f| relay f => @stderr} if @stderr
|
113
|
-
status
|
114
|
-
else
|
115
|
-
[status, IO.read(c['stdout']), IO.read(c['stderr'])]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def quote *args, &block
|
121
|
-
SystemUniversal.quote(*args, &block)
|
122
|
-
end
|
123
|
-
|
124
|
-
def new_thread cid, block
|
125
|
-
q = Queue.new
|
126
|
-
Thread.new(cid) do |cid|
|
127
|
-
current = Thread.current
|
128
|
-
current.abort_on_exception = true
|
129
|
-
q.push current
|
130
|
-
block.call cid
|
131
|
-
end
|
132
|
-
q.pop
|
133
|
-
end
|
134
|
-
|
135
|
-
def child_setup tmp
|
136
|
-
stdin = File.expand_path(File.join(tmp, 'stdin'))
|
137
|
-
stdout = File.expand_path(File.join(tmp, 'stdout'))
|
138
|
-
stderr = File.expand_path(File.join(tmp, 'stderr'))
|
139
|
-
program = File.expand_path(File.join(tmp, 'program'))
|
140
|
-
config = File.expand_path(File.join(tmp, 'config'))
|
141
|
-
|
142
|
-
if @stdin
|
143
|
-
open(stdin, 'w'){|f| relay @stdin => f}
|
144
|
-
else
|
145
|
-
FileUtils.touch stdin
|
146
|
-
end
|
147
|
-
FileUtils.touch stdout
|
148
|
-
FileUtils.touch stderr
|
149
|
-
|
150
|
-
c = {}
|
151
|
-
c['argv'] = @argv
|
152
|
-
c['env'] = @env
|
153
|
-
c['cwd'] = @cwd
|
154
|
-
c['stdin'] = stdin
|
155
|
-
c['stdout'] = stdout
|
156
|
-
c['stderr'] = stderr
|
157
|
-
c['program'] = program
|
158
|
-
open(config, 'w'){|f| Marshal.dump(c, f)}
|
159
|
-
|
160
|
-
open(program, 'w'){|f| f.write child_program(config)}
|
161
|
-
|
162
|
-
c
|
163
|
-
end
|
164
|
-
|
165
|
-
def quietly
|
166
|
-
v = $VERBOSE
|
167
|
-
$VERBOSE = nil
|
168
|
-
yield
|
169
|
-
ensure
|
170
|
-
$VERBOSE = v
|
171
|
-
end
|
172
|
-
|
173
|
-
def child_program config
|
174
|
-
<<-program
|
175
|
-
# encoding: utf-8
|
176
|
-
|
177
|
-
PIPE = STDOUT.dup
|
178
|
-
begin
|
179
|
-
config = Marshal.load(IO.read('#{ config }'))
|
180
|
-
|
181
|
-
argv = config['argv']
|
182
|
-
env = config['env']
|
183
|
-
cwd = config['cwd']
|
184
|
-
stdin = config['stdin']
|
185
|
-
stdout = config['stdout']
|
186
|
-
stderr = config['stderr']
|
187
|
-
|
188
|
-
Dir.chdir cwd if cwd
|
189
|
-
env.each{|k,v| ENV[k.to_s] = v.to_s} if env
|
190
|
-
|
191
|
-
STDIN.reopen stdin
|
192
|
-
STDOUT.reopen stdout
|
193
|
-
STDERR.reopen stderr
|
194
|
-
|
195
|
-
PIPE.puts "pid: \#{ Process.pid }"
|
196
|
-
PIPE.flush ### the process is ready yo!
|
197
|
-
PIPE.close
|
198
|
-
if RUBY_VERSION >= "1.9"
|
199
|
-
exec *argv
|
200
|
-
else
|
201
|
-
exec argv
|
202
|
-
end
|
203
|
-
rescue Exception => e
|
204
|
-
PIPE.write Marshal.dump(e) rescue nil
|
205
|
-
exit 42
|
206
|
-
end
|
207
|
-
program
|
208
|
-
end
|
209
|
-
|
210
|
-
def relay srcdst
|
211
|
-
src, dst, ignored = srcdst.to_a.first
|
212
|
-
if src.respond_to? 'read'
|
213
|
-
while((buf = src.read(8192))); dst << buf; end
|
214
|
-
else
|
215
|
-
if src.respond_to?(:each_line)
|
216
|
-
src.each_line{|buf| dst << buf}
|
217
|
-
else
|
218
|
-
src.each{|buf| dst << buf}
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def tmpdir d = Dir.tmpdir, max = 42, &b
|
224
|
-
i = -1 and loop{
|
225
|
-
i += 1
|
226
|
-
|
227
|
-
tmp = File.join d, "systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }"
|
228
|
-
|
229
|
-
begin
|
230
|
-
Dir.mkdir tmp
|
231
|
-
rescue Errno::EEXIST
|
232
|
-
raise if i >= max
|
233
|
-
next
|
234
|
-
end
|
235
|
-
|
236
|
-
break(
|
237
|
-
if b
|
238
|
-
begin
|
239
|
-
b.call tmp
|
240
|
-
ensure
|
241
|
-
FileUtils.rm_rf tmp unless SystemU.turd
|
242
|
-
end
|
243
|
-
else
|
244
|
-
tmp
|
245
|
-
end
|
246
|
-
)
|
247
|
-
}
|
248
|
-
end
|
249
|
-
|
250
|
-
def getopts opts = {}
|
251
|
-
lambda do |*args|
|
252
|
-
keys, default, ignored = args
|
253
|
-
catch(:opt) do
|
254
|
-
[keys].flatten.each do |key|
|
255
|
-
[key, key.to_s, key.to_s.intern].each do |key|
|
256
|
-
throw :opt, opts[key] if opts.has_key?(key)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
default
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# some monkeypatching for JRuby
|
266
|
-
if defined? JRUBY_VERSION
|
267
|
-
require 'jruby'
|
268
|
-
java_import org.jruby.RubyProcess
|
269
|
-
|
270
|
-
class SystemUniversal
|
271
|
-
def systemu
|
272
|
-
split_argv = JRuby::PathHelper.smart_split_command @argv
|
273
|
-
process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
|
274
|
-
|
275
|
-
stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
|
276
|
-
StreamReader.new(stream)
|
277
|
-
end
|
278
|
-
|
279
|
-
exit_code = process.wait_for
|
280
|
-
field = process.get_class.get_declared_field("pid")
|
281
|
-
field.set_accessible(true)
|
282
|
-
pid = field.get(process)
|
283
|
-
[
|
284
|
-
RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code, pid),
|
285
|
-
stdout.join,
|
286
|
-
stderr.join
|
287
|
-
]
|
288
|
-
end
|
289
|
-
|
290
|
-
class StreamReader
|
291
|
-
def initialize(stream)
|
292
|
-
@data = ""
|
293
|
-
@thread = Thread.new do
|
294
|
-
reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
|
295
|
-
|
296
|
-
while line = reader.read_line
|
297
|
-
@data << line << "\n"
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
def join
|
303
|
-
@thread.join
|
304
|
-
@data
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
SystemU = SystemUniversal unless defined? SystemU
|
313
|
-
Systemu = SystemUniversal unless defined? Systemu
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
if $0 == __FILE__
|
328
|
-
#
|
329
|
-
# date
|
330
|
-
#
|
331
|
-
date = %q( ruby -e" t = Time.now; STDOUT.puts t; STDERR.puts t " )
|
332
|
-
|
333
|
-
status, stdout, stderr = systemu date
|
334
|
-
p [status, stdout, stderr]
|
335
|
-
|
336
|
-
status = systemu date, 1=>(stdout = '')
|
337
|
-
p [status, stdout]
|
338
|
-
|
339
|
-
status = systemu date, 2=>(stderr = '')
|
340
|
-
p [status, stderr]
|
341
|
-
#
|
342
|
-
# sleep
|
343
|
-
#
|
344
|
-
sleep = %q( ruby -e" p(sleep(1)) " )
|
345
|
-
status, stdout, stderr = systemu sleep
|
346
|
-
p [status, stdout, stderr]
|
347
|
-
|
348
|
-
sleep = %q( ruby -e" p(sleep(42)) " )
|
349
|
-
status, stdout, stderr = systemu(sleep){|cid| Process.kill 9, cid}
|
350
|
-
p [status, stdout, stderr]
|
351
|
-
#
|
352
|
-
# env
|
353
|
-
#
|
354
|
-
env = %q( ruby -e" p ENV['A'] " )
|
355
|
-
status, stdout, stderr = systemu env, :env => {'A' => 42}
|
356
|
-
p [status, stdout, stderr]
|
357
|
-
#
|
358
|
-
# cwd
|
359
|
-
#
|
360
|
-
env = %q( ruby -e" p Dir.pwd " )
|
361
|
-
status, stdout, stderr = systemu env, :cwd => Dir.tmpdir
|
362
|
-
p [status, stdout, stderr]
|
363
|
-
end
|