Class: Mirage::Runner

Inherits:
Thor
  • Object
show all
Includes:
CLIBridge, WaitMethods
Defined in:
lib/mirage/client/runner.rb

Constant Summary collapse

RUBY_CMD =
ChildProcess.jruby? ? 'jruby' : 'ruby'

Instance Method Summary collapse

Methods included from WaitMethods

#wait_until

Methods included from CLIBridge

#kill, #mirage_process_ids, #processes_with_name

Instance Method Details

#startObject



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
# File 'lib/mirage/client/runner.rb', line 64

def start
  port = options[:port]
  process_ids = mirage_process_ids([port])
  unless process_ids.empty?
    warn "Mirage is already running: #{process_ids.values.join(",")}"
    return
  end

  mirage_server_file = "#{File.dirname(__FILE__)}/../../../mirage_server.rb"

  if ChildProcess.windows?
    command = ["cmd", "/C", "start", "mirage server port #{port}", RUBY_CMD, mirage_server_file]
  else
    command = [RUBY_CMD, mirage_server_file]
  end


  command = command.concat(options.to_a).flatten.collect { |arg| arg.to_s }
  ChildProcess.build(*command).start

  wait_until(:timeout_after => 30) { Mirage.running?(options) }

  begin
    Mirage::Client.new(options).prime
  rescue Mirage::InternalServerException => e
    puts "WARN: #{e.message}"
  end
end

#stopObject

Raises:



96
97
98
99
100
101
102
# File 'lib/mirage/client/runner.rb', line 96

def stop
  ports = options[:port].collect{|port| port=~/\d+/ ? port.to_i : port}
  process_ids = mirage_process_ids(ports)
  raise ClientError.new("Mirage is running on ports #{process_ids.keys.sort.join(", ")}. Please run mirage stop -p [PORT(s)] instead") if (process_ids.size > 1 && ports.empty?)
  process_ids.values.each { |process_id| kill process_id }
  wait_until { mirage_process_ids(options[:port]).empty? }
end