52 #include <boost/algorithm/string.hpp>
60 #include <sys/types.h>
72 "Usage: serverup [options] <server-name>\n\n"
74 " This program checks to see if the server, specified by <server-name>\n"
75 " is up. return 0 if true, 1 otherwise. <server-name> may be one of the\n"
76 " following values: fsbroker, hyperspace, master, global-master, \n"
77 " rangeserver, thriftbroker\n\n"
78 " master: checks for a master running on localhost\n"
79 " global-master: checks for a master running in the cluster (address is\n"
80 " fetched from hyperspace)\n"
84 static void init_options() {
86 (
"wait",
i32()->default_value(2000),
"Check wait time in ms")
87 (
"host",
str(),
"Specifies the hostname of the server(s)")
88 (
"display-address",
boo()->default_value(
false),
89 "Displays hostname and port of the server(s), then exits")
102 #ifdef HT_WITH_THRIFT
107 typedef Meta::list<AppPolicy, FsClientPolicy, HyperspaceClientPolicy,
114 InetAddr &addr,
int timeout_ms,
int wait_ms) {
117 conn_mgr->add(addr, timeout_ms, server);
119 if (!conn_mgr->wait_for_connection(addr, wait_ms))
124 HT_DEBUG_OUT <<
"Checking fsbroker at " << get_str(
"fs-host")
125 <<
':' << get_i16(
"fs-port") <<
HT_END;
142 if (get_bool(
"display-address")) {
143 std::cout << get_str(
"fs-host") <<
":" << get_i16(
"fs-port")
145 quick_exit(EXIT_SUCCESS);
150 if (!fs->wait_for_connection(wait_ms))
158 status.
get(&code, output);
164 quick_exit(EXIT_FAILURE);
172 Timer timer(max_wait_ms,
true);
175 String host =
"localhost";
178 std::vector<String> vec;
180 properties->set(
"Hyperspace.Replica.Host", vec);
183 if (get_bool(
"display-address")) {
184 std::cout << host <<
":" <<
185 properties->get_i16(
"Hyperspace.Replica.Port") << std::endl;
186 quick_exit(EXIT_SUCCESS);
189 hyperspace = make_shared<Hyperspace::Session>(conn_mgr->get_comm(),
properties);
191 if (!hyperspace->wait_for_connection(max_wait_ms))
195 error = hyperspace->status(status, &timer);
201 HT_THROW(error,
"getting hyperspace status");
207 Timer timer(wait_ms,
true);
209 if (get_bool(
"display-address")) {
210 std::cout << get_str(
"Hypertable.Master.Host") <<
":" <<
211 get_i16(
"Hypertable.Master.Port") << std::endl;
212 quick_exit(EXIT_SUCCESS);
216 hyperspace = make_shared<Hyperspace::Session>(conn_mgr->get_comm(),
properties);
217 if (!hyperspace->wait_for_connection(wait_ms))
224 boost::trim_if(toplevel_dir, boost::is_any_of(
"/"));
225 toplevel_dir =
String(
"/") + toplevel_dir;
229 toplevel_dir, wait_ms, app_queue,
238 master->
status(status, &timer);
239 status.
get(&code, text);
245 Timer timer(wait_ms,
true);
246 uint16_t port =
properties->get_i16(
"Hypertable.Master.Port");
254 if (get_bool(
"display-address")) {
255 std::cout << host <<
":" << port << std::endl;
256 quick_exit(EXIT_SUCCESS);
265 if (strcmp(host,
"localhost") && strcmp(host,
"127.0.0.1"))
272 pid_t pid = (pid_t)strtoul(pidstr.c_str(), 0, 0);
276 if (::kill(pid, 0) < 0)
283 master->
status(status, &timer);
284 status.
get(&code, text);
291 HT_DEBUG_OUT <<
"Checking rangeserver at "<< get_str(
"rs-host")
292 <<
':'<< get_i16(
"rs-port") <<
HT_END;
300 if (get_bool(
"display-address")) {
301 std::cout << get_str(
"rs-host") <<
":" << get_i16(
"rs-port") << std::endl;
302 quick_exit(EXIT_SUCCESS);
305 InetAddr addr(get_str(
"rs-host"), get_i16(
"rs-port"));
307 wait_for_connection(
"range server", conn_mgr, addr, wait_ms, wait_ms);
310 = make_shared<RangeServer::Client>(conn_mgr->get_comm(), wait_ms);
311 Timer timer(wait_ms,
true);
313 range_server->status(addr, status, timer);
316 status.
get(&code, text);
317 if (code > ready_status)
322 #ifdef HT_WITH_THRIFT
326 if (get_bool(
"display-address")) {
327 std::cout << get_str(
"thrift-host") <<
":" << get_i16(
"thrift-port")
329 quick_exit(EXIT_SUCCESS);
333 InetAddr addr(get_str(
"thrift-host"), get_i16(
"thrift-port"));
336 Thrift::Client client(get_str(
"thrift-host"), get_i16(
"thrift-port"));
337 ThriftGen::Namespace ns = client.open_namespace(
"sys");
338 client.get_table_id(table_id, ns,
"METADATA");
339 client.namespace_close(ns);
341 catch (ThriftGen::ClientException &e) {
344 catch (std::exception &e) {
355 #define CHECK_SERVER(_server_) do { \
356 try { check_##_server_(conn_mgr, wait_ms); } catch (Exception &e) { \
358 HT_DEBUG_OUT << e << HT_END; \
359 cout << #_server_ <<" - down" << endl; \
364 if (verbose) cout << #_server_ <<" - up" << endl; \
368 int main(
int argc,
char **argv) {
372 init_with_policies<Policies>(argc, argv);
374 bool silent = get_bool(
"silent");
375 uint32_t wait_ms = get_i32(
"wait");
377 bool verbose = get_bool(
"verbose");
380 conn_mgr->set_quiet_mode(silent);
382 properties->set(
"FsBroker.Timeout", (int32_t)wait_ms);
384 if (server_name ==
"fsbroker") {
387 else if (server_name ==
"hyperspace") {
390 else if (server_name ==
"global-master" || server_name ==
"global_master") {
393 else if (server_name ==
"master") {
396 else if (server_name ==
"rangeserver") {
399 else if (server_name ==
"thriftbroker") {
408 #ifdef HT_WITH_THRIFT
414 cout << (down ?
"false" :
"true") << endl;
418 quick_exit(EXIT_FAILURE);
Interface and base of config policy.
static const char * METADATA_ID
Holds Nagios-style program status information.
PropertiesPtr properties
This singleton map stores all options.
static bool read(const String &fname, String &contents)
Reads a whole file into a String.
std::string String
A String is simply a typedef to std::string.
Helper class for printing usage banners on the command line.
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Declarations for TableIdentifier and TableIdentifierManaged.
Po::typed_value< String > * str(String *v=0)
Declarations for RangeServerClient.
Code
Enumeration for status codes.
bool wait_for_connection(uint32_t max_wait_ms)
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
#define HT_EXPECT(_e_, _code_)
std::shared_ptr< Session > SessionPtr
const char * get_text(int error)
Returns a descriptive error message.
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Encapsulate an internet address.
Po::typed_value< int32_t > * i32(int32_t *v=0)
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Helpers to compose init policies; allow to combine two policies into one.
int main(int argc, char **argv)
A timer class to keep timeout states across AsyncComm related calls.
Logging routines and macros.
Compatibility Macros for C/C++.
Po::typed_value< bool > * boo(bool *v=0)
Initialization helper for applications.
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
bool defaulted(const String &name)
Check if a configuration value is defaulted.
void status(Status &status, Timer *timer=0)
Declarations for ConnectionManager.
#define HT_THROWF(_code_, _fmt_,...)
static Code string_to_code(std::string str)
void get(Code *code, std::string &text) const
Gets status code and text.
Internet address wrapper classes and utility functions.
Meta::list< MyPolicy, DefaultPolicy > Policies
Declarations for ReactorFactory.
A timer class to keep timeout states across AsyncComm related calls.
static String install_dir
The installation directory.
This is a generic exception class for Hypertable.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
Declarations for MasterClient This file contains declarations for MasterClient, a client interface cl...
Client interface to Master.
#define HT_ERRORF(msg,...)
Declarations for ApplicationQueue.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
std::shared_ptr< ConnectionInitializer > ConnectionInitializerPtr
Smart pointer to ConnectionInitializer.
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
A client for the ThriftBroker.
#define CHECK_SERVER(_server_)
int code() const
Returns the error code.