class Uc::Status
Attributes
paths[R]
use_pid[RW]
Public Class Methods
new(unicorn_paths, use_pid: false)
click to toggle source
# File lib/uc/status.rb, line 13 def initialize(unicorn_paths, use_pid: false) @paths = unicorn_paths @use_pid = use_pid end
Public Instance Methods
pid()
click to toggle source
# 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_file()
click to toggle source
# File lib/uc/status.rb, line 34 def pid_from_file @pid_from_file ||= read_pid end
running?()
click to toggle source
# File lib/uc/status.rb, line 18 def running? return process_running? pid if use_pid not ex_lock_available? end
stopped?()
click to toggle source
# File lib/uc/status.rb, line 38 def stopped? not running? end
to_s()
click to toggle source
# File lib/uc/status.rb, line 42 def to_s status = ( running? ? "Running pid #{pid}" : "Stopped" ) end
Private Instance Methods
ex_lock_available?()
click to toggle source
# File lib/uc/status.rb, line 48 def ex_lock_available? File.open( paths.lock_file, 'a+') do |f| ex_lock = f.flock(File::LOCK_EX|File::LOCK_NB) end end
fuser()
click to toggle source
# File lib/uc/status.rb, line 76 def fuser if File.exists? "/usr/sbin/fuser" return "/usr/sbin/fuser" else return "fuser" end end
fuser_pids()
click to toggle source
# File lib/uc/status.rb, line 61 def fuser_pids @fuser_pids ||= begin output = `#{fuser} #{paths.lock_file} 2>/dev/null` pids = output.strip.split.map { |pid| pid.to_i } end end
pid_valid?()
click to toggle source
# File lib/uc/status.rb, line 68 def pid_valid? if use_pid return true else fuser_pids.include?(pid_from_file) end end
read_pid()
click to toggle source
# File lib/uc/status.rb, line 54 def read_pid pid = (File.read paths.pid_file).to_i pid == 0 ? -1 : pid rescue return -1 end