Class: RackCheck::ServerManager

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rack_check/server_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#with_environment

Constructor Details

#initialize(context, ru_file) ⇒ ServerManager

Returns a new instance of ServerManager.



10
11
12
13
14
# File 'lib/rack_check/server_manager.rb', line 10

def initialize(context, ru_file)
  @ru_file = ru_file
  @stop_var = Concurrent::MVar.new
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/rack_check/server_manager.rb', line 8

def context
  @context
end

#ru_fileObject (readonly)

Returns the value of attribute ru_file.



8
9
10
# File 'lib/rack_check/server_manager.rb', line 8

def ru_file
  @ru_file
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rack_check/server_manager.rb', line 16

def run
  Thread.new do
    begin
      with_environment(ru_file) do |dir|
        @pid = Process.spawn context.app_server_command,
          in: '/dev/null',
          out: '/dev/null',
          err: '/dev/null',
          chdir: dir
        @stop_var.take
        Process.kill 'TERM', @pid
        Process.wait @pid
        @pid = nil
      end
    rescue => e
      $stderr.puts "App server thread exited: #{e.message}\n#{e.backtrace.join("\n")}"
    end
  end

  port = wait_for_port

  "http://localhost:#{port}"
end

#stopObject



40
41
42
43
44
45
# File 'lib/rack_check/server_manager.rb', line 40

def stop
  @stop_var.put true
  while check_port
    sleep 0.1
  end
end