HBASE-9577 Log process environment variable on HBase service startup

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1524873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-09-20 00:31:54 +00:00
parent 107e99b2ca
commit f5aca7f59f
3 changed files with 51 additions and 3 deletions

View File

@ -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");

View File

@ -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);

View File

@ -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<String> DEFAULT_SKIP_WORDS = new HashSet<String>() {
{
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"}.
* <p>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<String> skipWords = new HashSet<String>(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<String, String> 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 <code>run()</code>.