Class: DRbQS::Manage

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/drbqs/manage/manage.rb,
lib/drbqs/manage/ssh_shell.rb,
lib/drbqs/manage/send_signal.rb,
lib/drbqs/manage/ssh_execute.rb

Defined Under Namespace

Classes: NoServerRespond, NotSetURI, SSHExecute, SSHShell, SendSignal

Constant Summary collapse

WAIT_SERVER_TIME =
0.2
WAIT_MAX_NUMBER =
150

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Manage

+opts+ has keys :home and :uri.



19
20
21
22
23
# File 'lib/drbqs/manage/manage.rb', line 19

def initialize(opts = {})
  @opts = opts
  @config = nil
  @signal_sender = nil
end

Instance Method Details

#clear_processObject



106
107
108
# File 'lib/drbqs/manage/manage.rb', line 106

def clear_process
  config.list.clear_process_not_exist
end

#create_configObject



56
57
58
# File 'lib/drbqs/manage/manage.rb', line 56

def create_config
  config.save_sample
end

#list_processObject



102
103
104
# File 'lib/drbqs/manage/manage.rb', line 102

def list_process
  { :server => config.list.server.list, :node => config.list.node.list }
end

#server_respond?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/drbqs/manage/manage.rb', line 65

def server_respond?
  ret = nil
  begin
    if get_response
      ret = true
    end
  rescue DRbQS::Manage::NotSetURI
    raise
  rescue
  end
  ret
end

#set_home_directory(dir) ⇒ Object



29
30
31
# File 'lib/drbqs/manage/manage.rb', line 29

def set_home_directory(dir)
  @opts[:home] = dir
end

#set_uri(uri) ⇒ Object



25
26
27
# File 'lib/drbqs/manage/manage.rb', line 25

def set_uri(uri)
  @opts[:uri] = uri
end

#wait_server_process(pid = nil) ⇒ Object

If the server responds, this method returns true. If the server process does not exist, this method return nil. If the server process exists and there is no response, this method raises error.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/drbqs/manage/manage.rb', line 82

def wait_server_process(pid = nil)
  i = 0
  begin
    sleep(WAIT_SERVER_TIME)
    if pid
      unless DRbQS::Misc.process_running_normally?(pid)
        return nil
      end
    elsif server_data = config.list.server.get(@opts[:uri])
      pid = server_data[:pid]
    end
    i += 1
    if i > WAIT_MAX_NUMBER
      raise DRbQS::Manage::NoServerRespond,
      "We are waiting for #{WAIT_SERVER_TIME * WAIT_MAX_NUMBER} seconds, but the server of #{@opts[:uri]} does not respond."
    end
  end while !server_respond?
  true
end