Class: Cassie::Support::ServerProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/support/server_process.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid = nil) ⇒ ServerProcess

Starts a cassandra server process. #running? will be true if it started correctly.



29
30
31
32
33
34
35
36
37
38
# File 'lib/cassie/support/server_process.rb', line 29

def initialize(pid=nil)
  @pid = pid
  @errors = []

  if pid
    @running = true
  else
    start_cassandra
  end
end

Instance Attribute Details

#errorsArray<String> (readonly)

Returns The Cassandra output lines tagged with ERROR.

Returns:

  • (Array<String>)

    The Cassandra output lines tagged with ERROR



7
8
9
# File 'lib/cassie/support/server_process.rb', line 7

def errors
  @errors
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



1
2
3
# File 'lib/cassie/support/server_process.rb', line 1

def log_path
  @log_path
end

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/cassie/support/server_process.rb', line 5

def pid
  @pid
end

Class Method Details

.allArray<ServerProcess>

Scan the system for cassandra processes running

Returns:

Raises:

  • (RuntimeError)

    if scanning with ps system calls fails.



12
13
14
# File 'lib/cassie/support/server_process.rb', line 12

def self.all
  pids.map{|pid| new(pid)}
end

.log_pathObject

The path to the active cassandra binary’s log file Does not yet respect a configured log path, and assumes the path is relative to bin/casandra at ../logs/system.log



20
21
22
23
24
25
26
# File 'lib/cassie/support/server_process.rb', line 20

def self.log_path
  which = Cassie::Support::SystemCommand.new("which", ["cassandra"])
  which.succeed

  bin_path = which.output.tr("\n", '')
  bin_path.sub('bin/cassandra', 'logs/system.log')
end

Instance Method Details

#commandObject



61
62
63
# File 'lib/cassie/support/server_process.rb', line 61

def command
  details[:command]
end

#running?Boolean

Returns If the cassandra server started correctly. See #errors if false.

Returns:

  • (Boolean)

    If the cassandra server started correctly. See #errors if false.



41
42
43
# File 'lib/cassie/support/server_process.rb', line 41

def running?
  !!@running
end

#stopObject

Stops the cassandra server processes, synchronously.

Raises:

  • (RuntimeError)

    if the process could not be killed.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cassie/support/server_process.rb', line 47

def stop
  self.class.pids.each do|pid|
    Process.kill("TERM", pid)
    loop do
      sleep(0.1)
      begin
        Process.getpgid( pid )
      rescue Errno::ESRCH
        break
      end
    end
  end
end