diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java index a3cf7b386c1..886fde6b627 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java @@ -180,7 +180,7 @@ public class HMasterCommandLine extends ServerCommandLine { cluster.startup(); waitOnMasterThreads(cluster); } else { - logJVMInfo(); + logProcessInfo(getConf()); HMaster master = HMaster.constructMaster(masterClass, conf); if (master.isStopped()) { LOG.info("Won't bring the Master up as a shutdown is requested"); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java index dcc58e1a892..c51f4537252 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java @@ -57,7 +57,7 @@ public class HRegionServerCommandLine extends ServerCommandLine { LOG.warn("Not starting a distinct region server because " + HConstants.CLUSTER_DISTRIBUTED + " is false"); } else { - logJVMInfo(); + logProcessInfo(getConf()); HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf); Thread rsThread = HRegionServer.startRegionServer(hrs); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java index 98c9aba3d79..d8ae00e3799 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java @@ -18,8 +18,12 @@ */ package org.apache.hadoop.hbase.util; -import java.lang.management.RuntimeMXBean; import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,6 +40,15 @@ import org.apache.hadoop.util.ToolRunner; @InterfaceAudience.Private public abstract class ServerCommandLine extends Configured implements Tool { private static final Log LOG = LogFactory.getLog(ServerCommandLine.class); + @SuppressWarnings("serial") + private static final Set DEFAULT_SKIP_WORDS = new HashSet() { + { + add("secret"); + add("passwd"); + add("password"); + add("credential"); + } + }; /** * Implementing subclasses should return a usage string to print out. @@ -69,6 +82,41 @@ public abstract class ServerCommandLine extends Configured implements Tool { } } + /** + * Logs information about the currently running JVM process including + * the environment variables. Logging of env vars can be disabled by + * setting {@code "hbase.envvars.logging.disabled"} to {@code "true"}. + *

If enabled, you can also exclude environment variables containing + * certain substrings by setting {@code "hbase.envvars.logging.skipwords"} + * to comma separated list of such substrings. + */ + public static void logProcessInfo(Configuration conf) { + // log environment variables unless asked not to + if (conf == null || !conf.getBoolean("hbase.envvars.logging.disabled", false)) { + Set skipWords = new HashSet(DEFAULT_SKIP_WORDS); + if (conf != null) { + String[] confSkipWords = conf.getStrings("hbase.envvars.logging.skipwords"); + if (confSkipWords != null) { + skipWords.addAll(Arrays.asList(confSkipWords)); + } + } + + nextEnv: + for (Entry entry : System.getenv().entrySet()) { + String key = entry.getKey().toLowerCase(); + String value = entry.getValue().toLowerCase(); + // exclude variables which may contain skip words + for(String skipWord : skipWords) { + if (key.contains(skipWord) || value.contains(skipWord)) + continue nextEnv; + } + LOG.info("env:"+entry); + } + } + // and JVM info + logJVMInfo(); + } + /** * Parse and run the given command line. This may exit the JVM if * a nonzero exit code is returned from run().