summaryrefslogtreecommitdiff
path: root/src/tools/gceph.cc
blob: 5270813dd90cc4dbe6d176804baaf36426f78b9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
 * Copyright (C) 2010 Dreamhost
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include "common/config.h"
#include "tools/common.h"

#include <iostream>
#include <sstream>
#include <vector>

// tool/gui.cc
int run_gui(CephToolCtx *ctx, int argc, char **argv);

using std::vector;

static std::ostringstream gss;

static void usage()
{
  cerr << "usage: gceph [options]\n\n";
  cerr << "Runs the ceph graphical monitor\n";
  generic_client_usage(); // Will exit()
}

static void parse_gceph_args(vector<const char*> &args)
{
  std::vector<const char*>::iterator i;
  std::string val;
  for (i = args.begin(); i != args.end(); ) {
    if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
      usage();
    } else {
      ++i;
    }
  }
}

static int cephtool_run_gui(CephToolCtx *ctx, int argc,
			    const char **argv)
{
  ctx->log = &gss;
  ctx->slog = &gss;

  // TODO: make sure that we capture the log this generates in the GUI
  ctx->lock.Lock();
  send_observe_requests(ctx);
  ctx->lock.Unlock();

  return run_gui(ctx, argc, (char **)argv);
}

static CephToolCtx *ctx = NULL;

void ceph_tool_common_shutdown_wrapper()
{
  ceph_tool_messenger_shutdown();
  ceph_tool_common_shutdown(ctx);
}

int main(int argc, const char **argv)
{
  int ret = 0;

  vector<const char*> args;
  argv_to_vec(argc, argv, args);
  env_to_vec(args);

  global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
  common_init_finish(g_ceph_context);
  parse_gceph_args(args);

  ctx = ceph_tool_common_init(CEPH_TOOL_MODE_GUI, false);
  if (!ctx) {
    derr << "cephtool_common_init failed." << dendl;
    return 1;
  }

  atexit(ceph_tool_common_shutdown_wrapper);

  vec_to_argv(args, argc, argv);
  if (cephtool_run_gui(ctx, argc, argv))
    ret = 1;

  if (ceph_tool_messenger_shutdown())
    ret = 1;

  return ret;
}