mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject mesos git commit: Enabling IP Discovery command.
Date Fri, 24 Jul 2015 20:42:35 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 0942b055c -> 37f8545ac


Enabling IP Discovery command.

JIRA: MESOS-2902

It is sometimes useful to enable an external script to configure the
IP address the Mesos Master will bind to on the server, where it's not
desirable to set the --ip flag and/or a "wrapper" script is not a
viable option.

This patch adds an --ip_discovery_command to point to a local script
that will emit as its only output the IP address that the Master will
bind to: only spaces and newlines are allowed; further, as we cannot
use the `libprocess` sub-processing facilities, we cannot timeout
the script, should this block for long times (or even forever).

This will conflict with the --ip flag, so if both set, we will fail
with an appropriate error message.

Review: https://reviews.apache.org/r/36425


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/37f8545a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/37f8545a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/37f8545a

Branch: refs/heads/master
Commit: 37f8545acb3159020c79306cab899e357fcf73a7
Parents: 0942b05
Author: Marco Massenzio <marco@mesosphere.io>
Authored: Fri Jul 24 12:33:21 2015 -0700
Committer: Benjamin Hindman <benjamin.hindman@gmail.com>
Committed: Fri Jul 24 13:42:24 2015 -0700

----------------------------------------------------------------------
 docs/configuration.md | 13 ++++++++++--
 src/master/main.cpp   | 50 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 59 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/37f8545a/docs/configuration.md
----------------------------------------------------------------------
diff --git a/docs/configuration.md b/docs/configuration.md
index babbd2f..506bab1 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -87,12 +87,21 @@ If you have special compilation requirements, please refer to `./configure
--hel
       --ip=VALUE
     </td>
     <td>
-      IP address to listen on
-
+      IP address to listen on; this cannot be used in conjunction
+      with --ip_discovery_command.
     </td>
   </tr>
   <tr>
     <td>
+      --ip_discovery_command=VALUE
+    </td>
+    <td>
+      Optional IP discovery command: if set, it is expected to emit
+      the IP address which Master will try to bind to.  Cannot be used
+      in conjunction with --ip.
+    </td>
+  </tr>  <tr>
+    <td>
       --log_dir=VALUE
     </td>
     <td>

http://git-wip-us.apache.org/repos/asf/mesos/blob/37f8545a/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index fd4de4d..e05a472 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -97,6 +97,7 @@ using std::cerr;
 using std::cout;
 using std::endl;
 using std::move;
+using std::ostringstream;
 using std::set;
 using std::shared_ptr;
 using std::string;
@@ -133,6 +134,15 @@ int main(int argc, char** argv)
             "  zk://username:password@host1:port1,host2:port2,.../path\n"
             "  file:///path/to/file (where file contains one of the above)");
 
+  // Optional IP discover script that will set the Master IP.
+  // If set, its output is expected to be a valid parseable IP string.
+  Option<string> ip_discovery_command;
+  flags.add(&ip_discovery_command,
+      "ip_discovery_command",
+      "Optional IP discovery binary: if set, it is expected to emit\n"
+      "the IP address which Master will try to bind to.\n"
+      "Cannot be used in conjunction with --ip.");
+
   Try<Nothing> load = flags.load("MESOS_", argc, argv);
 
   if (load.isError()) {
@@ -167,13 +177,49 @@ int main(int argc, char** argv)
     }
   }
 
-  // Initialize libprocess.
-  if (ip.isSome()) {
+  if (ip_discovery_command.isSome() && ip.isSome()) {
+    EXIT(EXIT_FAILURE) << flags.usage(
+        "Only one of --ip or --ip_discovery_command should be specified");
+  }
+
+  if (ip_discovery_command.isSome()) {
+    ostringstream out;
+
+    // TODO(marco): Modify os::shell to be used in a less verbose
+    // fashion, see MESOS-3142.
+    Try<int> status = os::shell(&out, ip_discovery_command.get());
+
+    if (status.isError()) {
+      EXIT(EXIT_FAILURE)
+          << "Could not execute '" << ip_discovery_command.get()
+          << "': " << status.error();
+    } else if (WIFSIGNALED(status.get())) {
+      EXIT(EXIT_FAILURE)
+          << "Running '" << ip_discovery_command.get()
+          << "' was interruped by signal '"
+          << strsignal(WTERMSIG(status.get())) << "'";
+    } else if (WEXITSTATUS(status.get()) != EXIT_SUCCESS) {
+      EXIT(EXIT_FAILURE)
+          << "Failed to discover Master IP using '"
+          << ip_discovery_command.get() << "'; the script was either not found
"
+          << "or exited with an error code.\n"
+          << "Error code (127 typically indicates command not found): "
+          << stringify(WEXITSTATUS(status.get()));
+    }
+
+    const string ipAddress = strings::trim(out.str());
+
+    LOG(INFO) << "Configuring Mesos master to listen on IP '"
+              << ipAddress << "'";
+
+    os::setenv("LIBPROCESS_IP", ipAddress);
+  } else if (ip.isSome()) {
     os::setenv("LIBPROCESS_IP", ip.get());
   }
 
   os::setenv("LIBPROCESS_PORT", stringify(port));
 
+  // Initialize libprocess.
   process::initialize("master");
 
   logging::initialize(argv[0], flags, true); // Catch signals.


Mime
View raw message