class OneApm::Agent::RestartMonitor

Public Class Methods

need_restart?() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 29
def self.need_restart?
  @result = timestamp == restart_file_timestamp
  self.timestamp = restart_file_timestamp unless @result
  !@result
end
new() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 7
def initialize
  @lock = Mutex.new
  create_restart_file
end
touch() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 35
def self.touch
  !file_path.nil? && system("touch #{file_path}")
end

Private Class Methods

file_path() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 54
def self.file_path
  return nil if path.nil?
  @file_path ||= "#{path}/#{OneApm::Manager.config[:agent_restart_file_name]}"
end
find_or_create_path(path_setting, root) click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 63
  def self.find_or_create_path(path_setting, root)
    for abs_path in [ File.expand_path(path_setting),
                      File.expand_path(File.join(root, path_setting)) ] do
      if File.directory?(abs_path) || (Dir.mkdir(abs_path) rescue nil)
        return abs_path[%r{^(.*?)/?$}]
      end
    end
    nil
  end

end
path() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 59
def self.path 
  @path ||= find_or_create_path(OneApm::Manager.config[:agent_restart_file_path], OneApm::Probe.instance.root)
end
restart_file_timestamp() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 49
def self.restart_file_timestamp
  return 0 unless File.exist?(file_path)
  File.mtime(file_path).to_i
end
timestamp() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 41
def self.timestamp
  @timestamp || 0
end
timestamp=(timestamp) click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 45
def self.timestamp= timestamp
  @timestamp = timestamp
end

Public Instance Methods

create_restart_file() click to toggle source
# File lib/one_apm/agent/agent/restart_monitor.rb, line 12
def create_restart_file
  @lock.synchronize do
    begin
      file_path = OneApm::Agent::RestartMonitor.file_path
      return if file_path.nil?
      if !File.exist?(file_path) && system("touch #{file_path}")
        OneApm::Manager.logger.info "create #{file_path} successful."
      else
        OneApm::Manager.logger.debug "#{file_path} has exist."  
      end
       OneApm::Agent::RestartMonitor.timestamp = File.mtime(file_path).to_i
    rescue => e
      OneApm::Manager.logger.warn("create #{file_path} fail.", e)
    end
  end
end