Class: Explorer::IPCClient
- Inherits:
-
Object
- Object
- Explorer::IPCClient
- Includes:
- Celluloid::IO
- Defined in:
- lib/explorer/ipc_client.rb
Instance Method Summary collapse
- #cmd_add(label, cmd, dir = nil) ⇒ Object
- #cmd_list ⇒ Object
- #cmd_remove(label) ⇒ Object
- #cmd_start(label) ⇒ Object
- #cmd_stop(label) ⇒ Object
- #hostmap_add(map, host, port) ⇒ Object
- #hostmap_list ⇒ Object
- #hostmap_remove(domain) ⇒ Object
-
#initialize(socket_path = '/tmp/explorer_ipc') ⇒ IPCClient
constructor
A new instance of IPCClient.
- #shutdown ⇒ Object
- #tail(io = STDOUT) ⇒ Object
Constructor Details
#initialize(socket_path = '/tmp/explorer_ipc') ⇒ IPCClient
Returns a new instance of IPCClient.
9 10 11 12 |
# File 'lib/explorer/ipc_client.rb', line 9 def initialize(socket_path = '/tmp/explorer_ipc') @socket_path = socket_path @socket = UNIXSocket.open(socket_path) end |
Instance Method Details
#cmd_add(label, cmd, dir = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/explorer/ipc_client.rb', line 53 def cmd_add(label, cmd, dir=nil) msg = { command: 'cmd-add', label: label, cmd: cmd, dir: dir, } @socket.puts msg.to_json end |
#cmd_list ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/explorer/ipc_client.rb', line 87 def cmd_list msg = { command: 'cmd-list' } @socket.puts msg.to_json JSON.parse @socket.readline end |
#cmd_remove(label) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/explorer/ipc_client.rb', line 79 def cmd_remove(label) msg = { command: 'cmd-remove', label: label, } @socket.puts msg.to_json end |
#cmd_start(label) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/explorer/ipc_client.rb', line 63 def cmd_start(label) msg = { command: 'cmd-start', label: label, } @socket.puts msg.to_json end |
#cmd_stop(label) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/explorer/ipc_client.rb', line 71 def cmd_stop(label) msg = { command: 'cmd-stop', label: label, } @socket.puts msg.to_json end |
#hostmap_add(map, host, port) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/explorer/ipc_client.rb', line 22 def hostmap_add map, host, port msg = { command: 'map-add', map: map, host: host, port: port } @socket.puts msg.to_json end |
#hostmap_list ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/explorer/ipc_client.rb', line 14 def hostmap_list msg = { command: 'map-list' } @socket.puts msg.to_json JSON.parse @socket.readline end |
#hostmap_remove(domain) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/explorer/ipc_client.rb', line 32 def hostmap_remove domain msg = { command: 'map-remove', map: domain } @socket.puts msg.to_json end |
#shutdown ⇒ Object
95 96 97 |
# File 'lib/explorer/ipc_client.rb', line 95 def shutdown @socket.close if @socket end |
#tail(io = STDOUT) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/explorer/ipc_client.rb', line 40 def tail(io = STDOUT) msg = { command: 'cmd-tail' } @socket.puts msg.to_json loop do line = @socket.gets io.puts line end rescue IOError end |