Class: OneApm::Agent::RestartMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/agent/agent/restart_monitor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRestartMonitor

Returns a new instance of RestartMonitor.



7
8
9
10
# File 'lib/one_apm/agent/agent/restart_monitor.rb', line 7

def initialize
  @lock = Mutex.new
  create_restart_file
end

Class Method Details

.need_restart?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# 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

.touchObject



35
36
37
# File 'lib/one_apm/agent/agent/restart_monitor.rb', line 35

def self.touch
  !file_path.nil? && system("touch #{file_path}")
end

Instance Method Details

#create_restart_fileObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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