Class: Testjour::CLI::SlaveStart

Inherits:
BaseCommand show all
Defined in:
lib/testjour/commands/slave_start.rb

Defined Under Namespace

Classes: StopServer

Instance Attribute Summary

Attributes inherited from BaseCommand

#non_options, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

detailed_help, help, #option_parser, options

Constructor Details

#initialize(*args) ⇒ SlaveStart

Returns a new instance of SlaveStart.



20
21
22
23
# File 'lib/testjour/commands/slave_start.rb', line 20

def initialize(*args)
  Testjour.logger.debug "Runner command #{self.class}..."
  super
end

Class Method Details

.commandObject



16
17
18
# File 'lib/testjour/commands/slave_start.rb', line 16

def self.command
  "slave:start"
end

Instance Method Details

#register_signal_handlerObject



54
55
56
57
58
59
# File 'lib/testjour/commands/slave_start.rb', line 54

def register_signal_handler
  trap("TERM") do
    Testjour.logger.info "TERM signal received."
    raise StopServer.new
  end
end

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/testjour/commands/slave_start.rb', line 25

def run
  verify_not_a_git_repo
  
  original_working_directory = File.expand_path(".")
  
  pid_file = PidFile.new("./testjour_slave.pid")
  pid_file.verify_doesnt_exist
  at_exit { pid_file.remove }
  register_signal_handler

  logfile = File.expand_path("./testjour.log")
  Daemonize.daemonize(logfile)
  
  Dir.chdir(original_working_directory)
  pid_file.write
  
  Testjour.setup_logger
  Testjour::Bonjour.serve(Testjour::SlaveServer.start)
  DRb.thread.join
rescue StopServer
  exit 0
end

#verify_not_a_git_repoObject



48
49
50
51
52
# File 'lib/testjour/commands/slave_start.rb', line 48

def verify_not_a_git_repo
  return unless File.exists?("./.git")
  puts "!!! This directory looks like a git repository. This probably isn't where you want to start a testjour slave"
  exit 1
end