bitgirder-platform 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/tomcat7 CHANGED
@@ -429,18 +429,20 @@ class Daemon < RuntimeCommand
429
429
  private
430
430
  def await_start
431
431
 
432
- connected = 4.times.find do |i|
433
- begin
434
- TCPSocket::new( "localhost", @config.control_port ).close
435
- true
436
- rescue Errno::ECONNREFUSED
437
- code( "Server ctl port not up yet; waiting" )
438
- sleep( 2 ** i )
439
- false
440
- end
441
- end
442
-
443
- raise "Could not get a ctl port connection" unless connected
432
+ ports = [ @config.control_port ] +
433
+ [ :http_port, :https_port ].
434
+ map { |p| @config.send( p ) }.
435
+ select { |p| p }
436
+
437
+ code( "Awaiting connection on ports: #{ports}" )
438
+
439
+ ports.each do |p|
440
+ WaitCondition.wait_backoff( seed: 1, max_tries: 4 ) do
441
+ res = can_connect?( p )
442
+ code( "Got conn on :#{p}: #{res}" )
443
+ res
444
+ end or raise "Could not get connection on :#{p}"
445
+ end
444
446
  end
445
447
 
446
448
  private
@@ -486,42 +488,23 @@ class Daemon < RuntimeCommand
486
488
  end
487
489
 
488
490
  private
489
- def await_port_close( port )
490
-
491
- 3.times do |i|
492
- begin
493
- TCPSocket.new( "localhost", port ).close
494
- code( "Still got a connection at :#{port}; will retry" )
495
- sleep( 2 )
496
- rescue Errno::ECONNREFUSED
497
- return true
498
- end
499
- end
500
-
501
- return false
502
- end
503
-
504
- private
505
- def await_srv_close
491
+ def await_proc_exit( pid )
506
492
 
507
- to_check = [ @config.control_port ]
508
- to_check << @config.http_port if @config.http_port
509
- to_check << @config.https_port if @config.https_port
510
-
511
- # Returns true if and only if all ports are seen closed
512
- ! to_check.find do |port|
513
- ! await_port_close( port )
514
- end
493
+ pc = ProcessCheck.for_pid( pid )
494
+ # WaitCondition.wait_backoff( seed: 1, max_tries: 3 ) { ! pc.alive? }
495
+ WaitCondition.wait_backoff( seed: 1, max_tries: 3 ) {
496
+ res = ! pc.alive?
497
+ code( "tomcat #{pid} is stopped: #{res}" )
498
+ res
499
+ }
515
500
  end
516
501
 
517
502
  private
518
503
  def do_stop
519
504
 
520
- pid = get_current_pid
521
-
522
505
  send_shutdown
523
506
 
524
- unless await_srv_close
507
+ unless await_proc_exit( pid = get_current_pid )
525
508
  code( "Server appears to still be running; sending KILL to #{pid}" )
526
509
  Process.kill( "KILL", pid )
527
510
  end
@@ -1317,5 +1317,53 @@ class DefaultObjectPathFormatter
1317
1317
  end
1318
1318
  end
1319
1319
 
1320
+ class WaitCondition < BitGirderClass
1321
+
1322
+ private_class_method :new
1323
+
1324
+ def initialize( f, waiter, max_tries )
1325
+
1326
+ @f, @waiter = f, waiter
1327
+ @max_tries = positive( max_tries, :max_tries )
1328
+ end
1329
+
1330
+ public
1331
+ def execute
1332
+
1333
+ res = nil
1334
+
1335
+ @max_tries.times do |i|
1336
+ break if res = @f.call
1337
+ @waiter.call if i < @max_tries - 1
1338
+ end
1339
+
1340
+ res
1341
+ end
1342
+
1343
+ def self.create_and_exec( waiter, opts, blk )
1344
+
1345
+ raise "No block given" unless blk
1346
+ max_tries = has_key( opts, :max_tries )
1347
+
1348
+ self.send( :new, blk, waiter, max_tries ).execute
1349
+ end
1350
+
1351
+ def self.wait_poll( opts, &blk )
1352
+
1353
+ poll = positive( has_key( opts, :poll ), :poll )
1354
+ waiter = lambda { sleep( poll ) }
1355
+
1356
+ self.create_and_exec( waiter, opts, blk )
1357
+ end
1358
+
1359
+ def self.wait_backoff( opts, &blk )
1360
+
1361
+ seed = positive( has_key( opts, :seed ), :seed )
1362
+ waiter = lambda { sleep( seed ); seed *= 2 }
1363
+
1364
+ self.create_and_exec( waiter, opts, blk )
1365
+ end
1366
+ end
1367
+
1320
1368
  end
1321
1369
  end
data/lib/bitgirder/io.rb CHANGED
@@ -9,6 +9,7 @@ require 'json'
9
9
  require 'yaml'
10
10
  require 'base64'
11
11
  require 'tmpdir'
12
+ require 'socket'
12
13
 
13
14
  include BitGirder::Core
14
15
  include BitGirderMethods
@@ -353,6 +354,32 @@ end
353
354
 
354
355
  module_function :read_full
355
356
 
357
+ def can_connect?( *argv )
358
+
359
+ code( "In can_connect, argv: #{argv}" )
360
+ raise "Need at least a port" if argv.empty?
361
+
362
+ host = argv.first.is_a?( String ) ? argv.shift : "127.0.0.1"
363
+
364
+ raise "Need a port" if argv.empty?
365
+
366
+ unless ( port = argv.shift ).is_a?( Integer )
367
+ raise TypeError, "Invalid host or port value: #{port.class}"
368
+ end
369
+
370
+ begin
371
+ code( "Making connection" )
372
+ TCPSocket::new( host, port ).close
373
+ code( "Got conn" )
374
+ true
375
+ rescue Errno::ECONNREFUSED
376
+ code( "No conn" )
377
+ false
378
+ end
379
+ end
380
+
381
+ module_function :can_connect?
382
+
356
383
  class DataUnitError < StandardError; end
357
384
 
358
385
  class DataUnit < BitGirderClass
@@ -961,5 +988,38 @@ class UnixProcessBuilder < BitGirderClass
961
988
  end
962
989
  end
963
990
 
991
+ class ProcessCheck < BitGirderClass
992
+
993
+ private_class_method :new
994
+
995
+ def initialize( pid, ps_str )
996
+
997
+ @pid, @ps_str = pid, ps_str
998
+ end
999
+
1000
+ public
1001
+ def alive?
1002
+ self.class.ps_str_for( @pid ) == @ps_str
1003
+ end
1004
+
1005
+ def self.ps_str_for( pid )
1006
+
1007
+ res = `ps -p #{pid} -w -o command= -o lstart=`.chomp
1008
+ res = nil if res.empty?
1009
+
1010
+ unless $?.success? || ( ( ex = $?.exitstatus ) == 1 && res == nil )
1011
+ raise "Couldn't get ps info for #{pid} (ps exited #{ex}: #{res})"
1012
+ end
1013
+
1014
+ res
1015
+ end
1016
+
1017
+ def self.for_pid( pid )
1018
+
1019
+ ps_str = self.ps_str_for( pid )
1020
+ self.send( :new, pid, ps_str )
1021
+ end
1022
+ end
1023
+
964
1024
  end
965
1025
  end
data/lib/doc-gen18.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # Autogenerated docs on 2012-12-04 17:20:26 -0800
2
+ # Autogenerated docs on 2012-12-05 10:36:26 -0800
3
3
  #
4
4
 
5
5
  # This code is only included for rdoc purposes and would not normally get
data/lib/doc-gen20.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # Autogenerated docs on 2012-12-04 17:20:26 -0800
2
+ # Autogenerated docs on 2012-12-05 10:36:26 -0800
3
3
  #
4
4
 
5
5
  # This code is only included for rdoc purposes and would not normally get
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitgirder-platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: