Class: RackCheck::ServerManager
- Inherits:
-
Object
- Object
- RackCheck::ServerManager
- Includes:
- Helpers
- Defined in:
- lib/rack_check/server_manager.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#ru_file ⇒ Object
readonly
Returns the value of attribute ru_file.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(context, ru_file) ⇒ ServerManager
constructor
A new instance of ServerManager.
- #output ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(context, ru_file) ⇒ ServerManager
Returns a new instance of ServerManager.
11 12 13 14 15 |
# File 'lib/rack_check/server_manager.rb', line 11 def initialize(context, ru_file) @ru_file = ru_file @stop_var = Concurrent::MVar.new @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/rack_check/server_manager.rb', line 9 def context @context end |
#ru_file ⇒ Object (readonly)
Returns the value of attribute ru_file.
9 10 11 |
# File 'lib/rack_check/server_manager.rb', line 9 def ru_file @ru_file end |
Instance Method Details
#errors ⇒ Object
46 47 48 |
# File 'lib/rack_check/server_manager.rb', line 46 def errors @err&.read.strip end |
#output ⇒ Object
50 51 52 |
# File 'lib/rack_check/server_manager.rb', line 50 def output @out&.read.strip end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rack_check/server_manager.rb', line 17 def run Thread.new do begin with_environment(ru_file) do |dir| Dir.chdir(dir) do @pid, @in, @out, @err = Open4.popen4 context.app_server_command @stop_var.take Process.kill 'TERM', @pid Process.wait @pid @pid = nil end end rescue => e $stderr.puts "App server thread exited: #{e.}\n#{e.backtrace.join("\n")}" end end port = wait_for_port "http://localhost:#{port}" end |
#stop ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rack_check/server_manager.rb', line 39 def stop @stop_var.put true while check_port sleep 0.1 end end |