]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/main.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd_mirror / main.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "common/ceph_argparse.h"
5 #include "common/config.h"
6 #include "common/debug.h"
7 #include "common/errno.h"
8 #include "global/global_init.h"
9 #include "global/signal_handler.h"
10 #include "Mirror.h"
11
12 #include <vector>
13
14 rbd::mirror::Mirror *mirror = nullptr;
15
16 void usage() {
17 std::cout << "usage: rbd-mirror [options...]" << std::endl;
18 std::cout << "options:\n";
19 std::cout << " -m monaddress[:port] connect to specified monitor\n";
20 std::cout << " --keyring=<path> path to keyring for local cluster\n";
21 std::cout << " --log-file=<logfile> file to log debug output\n";
22 std::cout << " --debug-rbd-mirror=<log-level>/<memory-level> set rbd-mirror debug level\n";
23 generic_server_usage();
24 }
25
26 static void handle_signal(int signum)
27 {
28 if (mirror)
29 mirror->handle_signal(signum);
30 }
31
32 int main(int argc, const char **argv)
33 {
34 std::vector<const char*> args;
35 env_to_vec(args);
36 argv_to_vec(argc, argv, args);
37
38 auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT,
39 CODE_ENVIRONMENT_DAEMON,
40 CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
41
42 for (auto i = args.begin(); i != args.end(); ++i) {
43 if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
44 usage();
45 return EXIT_SUCCESS;
46 }
47 }
48
49 if (g_conf->daemonize) {
50 global_init_daemonize(g_ceph_context);
51 }
52 g_ceph_context->enable_perf_counter();
53
54 common_init_finish(g_ceph_context);
55
56 init_async_signal_handler();
57 register_async_signal_handler(SIGHUP, sighup_handler);
58 register_async_signal_handler_oneshot(SIGINT, handle_signal);
59 register_async_signal_handler_oneshot(SIGTERM, handle_signal);
60
61 std::vector<const char*> cmd_args;
62 argv_to_vec(argc, argv, cmd_args);
63
64 // disable unnecessary librbd cache
65 g_ceph_context->_conf->set_val_or_die("rbd_cache", "false");
66
67 mirror = new rbd::mirror::Mirror(g_ceph_context, cmd_args);
68 int r = mirror->init();
69 if (r < 0) {
70 std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl;
71 goto cleanup;
72 }
73
74 mirror->run();
75
76 cleanup:
77 unregister_async_signal_handler(SIGHUP, sighup_handler);
78 unregister_async_signal_handler(SIGINT, handle_signal);
79 unregister_async_signal_handler(SIGTERM, handle_signal);
80 shutdown_async_signal_handler();
81
82 delete mirror;
83
84 return r < 0 ? EXIT_SUCCESS : EXIT_FAILURE;
85 }