class Roma::Adm

Public Class Methods

new(cmd, port) click to toggle source
   # File lib/roma/tools/roma-adm.rb
 8 def initialize(cmd, port)
 9   @cmd = cmd.dup #to avoid frozen error
10   @port = port
11 end

Public Instance Methods

check_type() click to toggle source
   # File lib/roma/tools/roma-adm.rb
13 def check_type
14   # waiting value input command
15   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)/)
16 
17   case @cmd
18   when "balse", "shutdown" # yes/no check
19     make_command("halt_cmd")
20     @halt_cmd = true
21   when "start" # alias cmd
22     make_command("booting")
23     @alias = true
24   when require_value_cmd
25     make_command("value")
26   else
27     t = Thread.new do
28       loop{
29         print "."
30         sleep 1
31       }
32     end
33   end
34 end
send_command(host="localhost") click to toggle source
   # File lib/roma/tools/roma-adm.rb
36 def send_command(host="localhost")
37   if @alias
38     base_path = Pathname(__FILE__).dirname.parent.parent.parent.expand_path
39     `#{base_path}/#{@cmd}` # bash
40   elsif @halt_cmd
41     return `echo -e "#{@cmd}" | nc -i1 #{host} #{@port}` # bash
42   else
43     timeout(5) {
44       res = []
45       TCPSocket.open(host, @port) do |sock|
46         sock.puts @cmd
47         while select [sock], nil, nil, 0.5
48           res << sock.gets.chomp!
49         end
50       end
51       return res
52     }
53   end
54 end

Private Instance Methods

make_command(type) click to toggle source
   # File lib/roma/tools/roma-adm.rb
58 def make_command(type)
59   case type
60   when "halt_cmd"
61     puts("Are you sure?(yes/no)\r\n")
62     if STDIN.gets.chomp != "yes"
63       raise "confirmation was rejected"
64     else
65       @cmd.concat("\r\nyes\r\nyes\r\n")
66     end
67   when "booting"
68     puts("Please input hostname or ip address which is used for ROMA.\r\n  Ex.) roma_serverA, 192.168.33.11\r\n")
69     hostname = STDIN.gets.chomp
70     puts("Please input PATH of config.rb.\r\n  Ex.) /home/roma/config.rb\r\n")
71     config_path = STDIN.gets.chomp
72     @cmd = "bin/romad #{hostname} -p #{@port} -d --config #{config_path}"
73   when "value"
74     puts("Please input value.\r\n")
75     value = STDIN.gets.chomp
76     @cmd.concat("\r\n#{value}\r\n")
77   end
78 end