1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.LocalHBaseCluster;
28 import org.apache.hadoop.hbase.util.ServerCommandLine;
29
30
31
32
33
34 @InterfaceAudience.Private
35 public class HRegionServerCommandLine extends ServerCommandLine {
36 private static final Log LOG = LogFactory.getLog(HRegionServerCommandLine.class);
37
38 private final Class<? extends HRegionServer> regionServerClass;
39
40 private static final String USAGE =
41 "Usage: HRegionServer [-D conf.param=value] start";
42
43 public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) {
44 this.regionServerClass = clazz;
45 }
46
47 protected String getUsage() {
48 return USAGE;
49 }
50
51 private int start() throws Exception {
52 Configuration conf = getConf();
53 try {
54
55
56 if (LocalHBaseCluster.isLocal(conf)) {
57 LOG.warn("Not starting a distinct region server because "
58 + HConstants.CLUSTER_DISTRIBUTED + " is false");
59 } else {
60 logProcessInfo(getConf());
61 HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf);
62 Thread rsThread = HRegionServer.startRegionServer(hrs);
63
64 rsThread.join();
65 if (hrs.isAborted()) {
66 throw new RuntimeException("HRegionServer Aborted");
67 }
68 }
69 } catch (Throwable t) {
70 LOG.error("Region server exiting", t);
71 return 1;
72 }
73 return 0;
74 }
75
76 public int run(String args[]) throws Exception {
77 if (args.length != 1) {
78 usage(null);
79 return 1;
80 }
81
82 String cmd = args[0];
83
84 if ("start".equals(cmd)) {
85 return start();
86 } else if ("stop".equals(cmd)) {
87 System.err.println(
88 "To shutdown the regionserver run " +
89 "bin/hbase-daemon.sh stop regionserver or send a kill signal to" +
90 "the regionserver pid");
91 return 1;
92 } else {
93 usage("Unknown command: " + args[0]);
94 return 1;
95 }
96 }
97 }