3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.util
;
21 import java
.lang
.management
.ManagementFactory
;
22 import java
.lang
.management
.RuntimeMXBean
;
23 import java
.util
.Arrays
;
24 import java
.util
.HashSet
;
25 import java
.util
.Locale
;
26 import java
.util
.Map
.Entry
;
29 import org
.apache
.commons
.logging
.Log
;
30 import org
.apache
.commons
.logging
.LogFactory
;
31 import org
.apache
.hadoop
.hbase
.classification
.InterfaceAudience
;
32 import org
.apache
.hadoop
.conf
.Configuration
;
33 import org
.apache
.hadoop
.conf
.Configured
;
34 import org
.apache
.hadoop
.hbase
.HBaseConfiguration
;
35 import org
.apache
.hadoop
.util
.Tool
;
36 import org
.apache
.hadoop
.util
.ToolRunner
;
39 * Base class for command lines that start up various HBase daemons.
41 @InterfaceAudience.Private
42 public abstract class ServerCommandLine
extends Configured
implements Tool
{
43 private static final Log LOG
= LogFactory
.getLog(ServerCommandLine
.class);
44 @SuppressWarnings("serial")
45 private static final Set
<String
> DEFAULT_SKIP_WORDS
= new HashSet
<String
>() {
55 * Implementing subclasses should return a usage string to print out.
57 protected abstract String
getUsage();
60 * Print usage information for this command line.
62 * @param message if not null, print this message before the usage info.
64 protected void usage(String message
) {
65 if (message
!= null) {
66 System
.err
.println(message
);
67 System
.err
.println("");
70 System
.err
.println(getUsage());
74 * Log information about the currently running JVM.
76 public static void logJVMInfo() {
77 // Print out vm stats before starting up.
78 RuntimeMXBean runtime
= ManagementFactory
.getRuntimeMXBean();
79 if (runtime
!= null) {
80 LOG
.info("vmName=" + runtime
.getVmName() + ", vmVendor=" +
81 runtime
.getVmVendor() + ", vmVersion=" + runtime
.getVmVersion());
82 LOG
.info("vmInputArguments=" + runtime
.getInputArguments());
87 * Logs information about the currently running JVM process including
88 * the environment variables. Logging of env vars can be disabled by
89 * setting {@code "hbase.envvars.logging.disabled"} to {@code "true"}.
90 * <p>If enabled, you can also exclude environment variables containing
91 * certain substrings by setting {@code "hbase.envvars.logging.skipwords"}
92 * to comma separated list of such substrings.
94 public static void logProcessInfo(Configuration conf
) {
95 // log environment variables unless asked not to
96 if (conf
== null || !conf
.getBoolean("hbase.envvars.logging.disabled", false)) {
97 Set
<String
> skipWords
= new HashSet
<>(DEFAULT_SKIP_WORDS
);
99 String
[] confSkipWords
= conf
.getStrings("hbase.envvars.logging.skipwords");
100 if (confSkipWords
!= null) {
101 skipWords
.addAll(Arrays
.asList(confSkipWords
));
106 for (Entry
<String
, String
> entry
: System
.getenv().entrySet()) {
107 String key
= entry
.getKey().toLowerCase(Locale
.ROOT
);
108 String value
= entry
.getValue().toLowerCase(Locale
.ROOT
);
109 // exclude variables which may contain skip words
110 for(String skipWord
: skipWords
) {
111 if (key
.contains(skipWord
) || value
.contains(skipWord
))
114 LOG
.info("env:"+entry
);
122 * Parse and run the given command line. This may exit the JVM if
123 * a nonzero exit code is returned from <code>run()</code>.
125 public void doMain(String args
[]) {
127 int ret
= ToolRunner
.run(HBaseConfiguration
.create(), this, args
);
131 } catch (Exception e
) {
132 LOG
.error("Failed to run", e
);