Class: Lightpanda::Process
- Inherits:
-
Object
- Object
- Lightpanda::Process
- Defined in:
- lib/lightpanda/process.rb
Constant Summary collapse
- READY_PATTERN =
/server running.*address=(\d+\.\d+\.\d+\.\d+:\d+)/
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#ws_url ⇒ Object
readonly
Returns the value of attribute ws_url.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(options) ⇒ Process
constructor
A new instance of Process.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Process
Returns a new instance of Process.
9 10 11 12 13 14 15 16 17 |
# File 'lib/lightpanda/process.rb', line 9 def initialize() = @pid = nil @ws_url = nil @stdout_r = nil @stdout_w = nil @stderr_r = nil @stderr_w = nil end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/lightpanda/process.rb', line 7 def pid @pid end |
#ws_url ⇒ Object (readonly)
Returns the value of attribute ws_url.
7 8 9 |
# File 'lib/lightpanda/process.rb', line 7 def ws_url @ws_url end |
Instance Method Details
#alive? ⇒ Boolean
49 50 51 52 53 54 55 56 |
# File 'lib/lightpanda/process.rb', line 49 def alive? return false unless @pid ::Process.kill(0, @pid) true rescue Errno::ESRCH, Errno::EPERM false end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lightpanda/process.rb', line 19 def start binary_path = .browser_path || Binary.find_or_download raise BinaryNotFoundError, "Lightpanda binary not found" unless binary_path @stdout_r, @stdout_w = IO.pipe @stderr_r, @stderr_w = IO.pipe @pid = spawn_process(binary_path) @stdout_w.close @stderr_w.close wait_for_ready end |
#stop ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lightpanda/process.rb', line 35 def stop return unless @pid begin ::Process.kill("TERM", @pid) ::Process.wait(@pid) rescue Errno::ESRCH, Errno::ECHILD # Process already dead end cleanup_pipes @pid = nil end |