This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 70986a9 Draft utility module
70986a9 is described below
commit 70986a9ce0a68c7aec45b4e3b74dc10e57fd7b67
Author: Sebb <[email protected]>
AuthorDate: Mon Sep 21 11:47:03 2020 +0100
Draft utility module
---
lib/whimsy/asf/active.rb | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/lib/whimsy/asf/active.rb b/lib/whimsy/asf/active.rb
new file mode 100644
index 0000000..b487bf9
--- /dev/null
+++ b/lib/whimsy/asf/active.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+# utility methods **DRAFT**
+
+require 'socket'
+require 'resolv'
+
+# common methods
+module Whimsy
+
+ # Are we the active node?
+ 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
+
+ # this hostname
+ def self.hostname
+ `hostname` # TODO: could be cached?
+ end
+
+end
+
+# for debugging purposes
+if __FILE__ == $0
+ puts Whimsy.active?
+ puts Whimsy.hostname
+end
\ No newline at end of file