module Status

common methods

Public Class Methods

active?() click to toggle source

Are we the active node?

# File lib/whimsy/asf/status.rb, line 12
def self.active?
  Resolv::DNS.open do |rs|
    active = rs.getaddress("whimsy.apache.org") # Official hostname as IP
    current = rs.getaddress(Socket.gethostname) rescue nil # local as IP
    return current == active
  end
end
hostname() click to toggle source

this hostname

# File lib/whimsy/asf/status.rb, line 21
def self.hostname
  `hostname`.chomp # TODO: could be cached?
end
migrating?() click to toggle source

are we migrating?

# File lib/whimsy/asf/status.rb, line 26
def self.migrating?
  false # Edit as needed
end
testnode?() click to toggle source

are we a test node?

# File lib/whimsy/asf/status.rb, line 31
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 41
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