module Status
common methods
Constants
- ACTIVE_HOSTNAME
Public Class Methods
active?()
click to toggle source
Are we the active node? i.e. is our IP address the same as that of the active node
# File lib/whimsy/asf/status.rb, line 18 def self.active? Resolv::DNS.open do |rs| active = rs.getaddress(ACTIVE_HOSTNAME) # Official hostname as IP; might change during run begin @currentIP ||= rs.getaddress(hostname) # local as IP; should not change during a run rescue Resolv::ResolvError => e # allow this to fail on a test node raise unless testnode? $stderr.puts "WARNING: Failed to resolve local IP address: #{e}" end return @currentIP == active end end
activeIP()
click to toggle source
# File lib/whimsy/asf/status.rb, line 72 def self.activeIP # intended for CLI testing Resolv::DNS.open.getaddress(ACTIVE_HOSTNAME) end
currentIP()
click to toggle source
# File lib/whimsy/asf/status.rb, line 61 def self.currentIP # intended for CLI testing Resolv::DNS.open do |rs| begin @currentIP ||= rs.getaddress(hostname) # local as IP; should not change during a run rescue Resolv::ResolvError => e # allow this to fail on a test node raise unless testnode? $stderr.puts "WARNING: Failed to resolve local IP address: #{e}" end end end
hostname()
click to toggle source
this hostname
# File lib/whimsy/asf/status.rb, line 32 def self.hostname @hostname ||= Socket.gethostname @hostname end
migrating?()
click to toggle source
are we migrating?
# File lib/whimsy/asf/status.rb, line 38 def self.migrating? # This is used to disable updates, see self.updates_disallowed_reason File.exist? '/srv/whimsy/migrating.txt' # default is false end
testnode?()
click to toggle source
are we a test node?
# File lib/whimsy/asf/status.rb, line 43 def self.testnode? # Assume test nodes are not called whimsy...[.apache.org] hostname !~ %r{^whimsy.*(\.apache\.org)?$} end
updates_disallowed_reason()
click to toggle source
If local updates are not allowed, return reason string, else nil nil if:
-
active node
-
not migrating
-
or testnode
# File lib/whimsy/asf/status.rb, line 53 def self.updates_disallowed_reason return nil if testnode? return 'Service temporarily unavailable due to migration.' if migrating? return 'Service unavailable on this node. Please ensure you have logged in to the correct host.' unless active? nil end