Class: Roma::Adm
- Inherits:
-
Object
- Object
- Roma::Adm
- Defined in:
- lib/roma/tools/roma-adm.rb
Instance Method Summary collapse
- #check_type ⇒ Object
-
#initialize(cmd, port) ⇒ Adm
constructor
A new instance of Adm.
- #send_command(host = "localhost") ⇒ Object
Constructor Details
#initialize(cmd, port) ⇒ Adm
Returns a new instance of Adm.
8 9 10 11 |
# File 'lib/roma/tools/roma-adm.rb', line 8 def initialize(cmd, port) @cmd = cmd.dup #to avoid frozen error @port = port end |
Instance Method Details
#check_type ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/roma/tools/roma-adm.rb', line 13 def check_type # waiting value input command require_value_cmd = Regexp.new(/^(set|add|replace|append|prepend|cas|alist_delete|alist_include\?|alist_insert|alist_sized_insert|alist_swap_and_insert|alist_swap_and_sized_insert|alist_join_with_time|alist_join|alist_push|alist_sized_push|alist_swap_and_push|alist_update_at)/) case @cmd when "balse", "shutdown" # yes/no check make_command("halt_cmd") @halt_cmd = true when "start" # alias cmd make_command("booting") @alias = true when require_value_cmd make_command("value") else t = Thread.new do loop{ print "." sleep 1 } end end end |
#send_command(host = "localhost") ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/roma/tools/roma-adm.rb', line 36 def send_command(host="localhost") if @alias base_path = Pathname(__FILE__).dirname.parent.parent.parent. `#{base_path}/#{@cmd}` # bash elsif @halt_cmd return `echo -e "#{@cmd}" | nc -i1 #{host} #{@port}` # bash else timeout(5) { res = [] TCPSocket.open(host, @port) do |sock| sock.puts @cmd while select [sock], nil, nil, 0.5 res << sock.gets.chomp! end end return res } end end |