whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Check if we are the master node
Date Sun, 14 May 2017 14:22:08 GMT
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  6a360d5   Check if we are the master node
6a360d5 is described below

commit 6a360d5bcc3571ac2e334ea4af2b119f2f48cb6f
Author: Sebb <sebb@apache.org>
AuthorDate: Sun May 14 15:22:06 2017 +0100

    Check if we are the master node
---
 www/status/index.cgi | 10 +++++++++-
 www/whimsy.rb        | 17 +++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/www/status/index.cgi b/www/status/index.cgi
index 9f4ded6..fc99c7a 100755
--- a/www/status/index.cgi
+++ b/www/status/index.cgi
@@ -34,6 +34,14 @@ git_repo = `git ls-remote origin master`.strip rescue "?"
 
 hostname = `hostname`
 
+# Are we the master node?
+begin
+  require_relative '../whimsy'
+  master = Whimsy.master?
+  rescue LoadError, StandardError => e
+    master = e
+end
+
 # What the browser sees:
 print <<-EOF
 <!DOCTYPE html>
@@ -54,7 +62,7 @@ print <<-EOF
     <a href="/">
       <img alt="Whimsy logo" title="Whimsy logo" src="../whimsy.svg" class="logo"/>
     </a>
-    <h1>Whimsy Status for #{hostname}</h1>
+    <h1>Whimsy Status for #{hostname} (master=#{master})</h1>
 
     <div class="list-group list-group-root well">
       Loading...
diff --git a/www/whimsy.rb b/www/whimsy.rb
new file mode 100644
index 0000000..fb5dc06
--- /dev/null
+++ b/www/whimsy.rb
@@ -0,0 +1,17 @@
+require 'socket'
+require 'resolv'
+module Whimsy
+  # Are we the master node?
+  def self.master?()
+    Resolv::DNS.open do |rs|
+      master = rs.getaddress("whimsy.apache.org") # Official hostname as IP
+      current = rs.getaddress(Socket.gethostname) rescue nil # local as IP
+      return current == master
+    end
+  end
+end
+
+# for debugging purposes
+if __FILE__ == $0
+  puts Whimsy.master?
+end
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message