Module: Contrast::Utils::OS

Includes:
Components::Interface
Defined in:
lib/contrast/utils/os.rb

Overview

Simple utility used to make OS calls and determine state. For that state which will not change at runtime, such as the operating system, the Utility memozies to avoid multiple lookups.

Class Method Summary collapse

Methods included from Components::Interface

included

Class Method Details

.running?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/contrast/utils/os.rb', line 16

def running?
  result = false
  with_contrast_scope do
    process = `ps aux | grep contrast-servic[e]`
    processes = process.split("\n")
    result = !processes.empty? && processes.any? { |process_descriptor| !process_descriptor.include?('grep') }
  end
  result
end

.zombie_pidsObject

check if service was killed and is a zombie process returns an array of zombie process PIDs as strings; empty array if there are none



28
29
30
31
32
33
# File 'lib/contrast/utils/os.rb', line 28

def zombie_pids
  with_contrast_scope do
    zombie_pid_list = `ps aux | grep contrast-servic[e] | grep Z | awk '{print $2}'` # retrieve pid of service processes
    zombie_pid_list.split("\n")
  end
end