Class: Harbour::Port
- Inherits:
-
Object
- Object
- Harbour::Port
- Defined in:
- lib/harbour.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(port) ⇒ Port
constructor
A new instance of Port.
- #kill!(options = {}) ⇒ Object
- #open? ⇒ Boolean
- #pid ⇒ Object
- #term!(options = {}) ⇒ Object
Constructor Details
#initialize(port) ⇒ Port
Returns a new instance of Port.
7 8 9 |
# File 'lib/harbour.rb', line 7 def initialize(port) @port = port end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/harbour.rb', line 5 def port @port end |
Instance Method Details
#kill!(options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/harbour.rb', line 26 def kill!( = {}) return nil unless open? command "kill -9 #{pid}" ensure_open([:timeout] || 10) end |
#open? ⇒ Boolean
11 12 13 |
# File 'lib/harbour.rb', line 11 def open? command "nc -z localhost #{port}" end |
#pid ⇒ Object
15 16 17 18 |
# File 'lib/harbour.rb', line 15 def pid return nil unless open? `lsof -P | grep ':#{port}' | grep 'LISTEN' | awk '{print $2}'` end |
#term!(options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/harbour.rb', line 20 def term!( = {}) return nil unless open? command "kill #{pid}" ensure_open([:timeout] || 10) end |