Class: Uc::Status

Inherits:
Object
  • Object
show all
Includes:
Logger, ShellHelper
Defined in:
lib/uc/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#event_queue, event_stream, #event_stream, logger, #logger, stderr, #stderr

Methods included from ShellHelper

#cmd, #kill, #process_running?

Constructor Details

#initialize(unicorn_paths, use_pid: false) ⇒ Status

Returns a new instance of Status.



13
14
15
16
# File 'lib/uc/status.rb', line 13

def initialize(unicorn_paths, use_pid: false)
  @paths =  unicorn_paths
  @use_pid = use_pid
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



10
11
12
# File 'lib/uc/status.rb', line 10

def paths
  @paths
end

#use_pidObject

Returns the value of attribute use_pid.



11
12
13
# File 'lib/uc/status.rb', line 11

def use_pid
  @use_pid
end

Instance Method Details

#pidObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/uc/status.rb', line 23

def pid
  pid = pid_from_file
  if pid_valid?
    return pid
  else
    logger.debug "pids holding unicorn.lock => #{fuser_pids.join(' ')}"
    logger.debug "pid from file => #{pid}"
    raise ::Uc::Error, "stale pid #{pid}"
  end
end

#pid_from_fileObject



34
35
36
# File 'lib/uc/status.rb', line 34

def pid_from_file
  @pid_from_file ||= read_pid
end

#running?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/uc/status.rb', line 18

def running?
  return process_running? pid if use_pid
  not ex_lock_available?
end

#stopped?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/uc/status.rb', line 38

def stopped?
  not running?
end

#to_sObject



42
43
44
# File 'lib/uc/status.rb', line 42

def to_s
  status = ( running? ? "Running pid #{pid}" : "Stopped" )
end