module Status
common methods
Constants
- ACTIVE_HOSTNAME
Public Class Methods
Source
# 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
Are we the active node? i.e. is our IP address the same as that of the active node
Source
# File lib/whimsy/asf/status.rb, line 72 def self.activeIP # intended for CLI testing Resolv::DNS.open.getaddress(ACTIVE_HOSTNAME) end
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
Source
# File lib/whimsy/asf/status.rb, line 32 def self.hostname @hostname ||= Socket.gethostname @hostname end
this hostname
Source
# 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
are we migrating?
Source
# File lib/whimsy/asf/status.rb, line 77 def self.notice path = '/srv/whimsy/www/notice.txt' if File.exist? path begin File.open(path) do |fh| return fh.readline.chomp, '/notice.txt' end rescue EOFError end end nil end
return notice file header and href path or nil
Source
# 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
are we a test node?
Source
# File lib/whimsy/asf/status.rb, line 53 def self.updates_disallowed_reason return 'Updates unavailable due to migration.' if migrating? return nil if testnode? return 'Updates unavailable on this node. Please ensure you have logged in to the correct host.' unless active? nil end
If local updates are not allowed, return reason string, else nil nil if:
-
active node
-
not migrating
-
or testnode