Class: TTCluster::RestartCommand

Inherits:
BaseCommand show all
Defined in:
lib/ttcluster/restart_command.rb

Overview

‘restart’ command implementation.

Instance Method Summary collapse

Constructor Details

#initialize(runner, port) ⇒ RestartCommand

Save runner and port for ‘restart’ run.



17
18
19
20
# File 'lib/ttcluster/restart_command.rb', line 17

def initialize(runner, port)
  super(runner)
  @port = port
end

Instance Method Details

#runObject

Restart ttcluster server.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ttcluster/restart_command.rb', line 24

def run
  chdir_to_ttbase

  statuses = get_statuses(@port)

  puts "TTCluster Restart:"
  statuses.each do |port, status|
    msg =
    case status
    when /^(running|mismatch) pid\((\d+)\)/
      stat, pid = $1, $2
      remove_pid_file(port) if stat == "mismatch"
      if stop_server(pid.to_i)
        sleep 0.2
        pid = start_server(port)
        pid>0 ? (MSG_RESTARTED_SERVER % pid) : MSG_FAILED_TO_RESTART_SERVER
      else
        MSG_FAILED_TO_STOP_SERVER % pid
      end
    when /^not running/
      pid = start_server(port)
      pid>0 ? (MSG_STARTED_SERVER % pid) : MSG_FAILED_TO_START_SERVER
    when /^stale pid\((\d+)\)/
      remove_pid_file(port)
      pid = start_server(port)
      pid>0 ? (MSG_STARTED_SERVER % pid) : MSG_FAILED_TO_START_SERVER
    end

    puts "  port(#{port}) => #{msg}"
  end
end