1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/ceph_argparse.h"
5 #include "common/config.h"
6 #include "common/debug.h"
7 #include "common/errno.h"
8 #include "common/async/context_pool.h"
9 #include "common/Preforker.h"
10 #include "global/global_init.h"
11 #include "global/signal_handler.h"
12 #include "mon/MonClient.h"
13 #include "msg/Messenger.h"
21 std::cout
<< "usage: cephfs-mirror [options...]" << std::endl
;
22 std::cout
<< "options:\n";
23 std::cout
<< " --mon-host monaddress[:port] connect to specified monitor\n";
24 std::cout
<< " --keyring=<path> path to keyring for local cluster\n";
25 std::cout
<< " --log-file=<logfile> file to log debug output\n";
26 std::cout
<< " --debug-cephfs-mirror=<log-level>/<memory-level> set cephfs-mirror debug level\n";
27 generic_server_usage();
30 cephfs::mirror::Mirror
*mirror
= nullptr;
32 static void handle_signal(int signum
) {
34 mirror
->handle_signal(signum
);
38 int main(int argc
, const char **argv
) {
39 auto args
= argv_to_vec(argc
, argv
);
41 cerr
<< argv
[0] << ": -h or --help for usage" << std::endl
;
45 if (ceph_argparse_need_usage(args
)) {
50 auto cct
= global_init(nullptr, args
, CEPH_ENTITY_TYPE_CLIENT
,
51 CODE_ENVIRONMENT_DAEMON
,
52 CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS
);
55 if (global_init_prefork(g_ceph_context
) >= 0) {
57 int r
= forker
.prefork(err
);
59 cerr
<< err
<< std::endl
;
62 if (forker
.is_parent()) {
63 g_ceph_context
->_log
->start();
64 if (forker
.parent_wait(err
) != 0) {
69 global_init_postfork_start(g_ceph_context
);
72 common_init_finish(g_ceph_context
);
74 bool daemonize
= g_conf().get_val
<bool>("daemonize");
76 global_init_postfork_finish(g_ceph_context
);
80 init_async_signal_handler();
81 register_async_signal_handler(SIGHUP
, handle_signal
);
82 register_async_signal_handler_oneshot(SIGINT
, handle_signal
);
83 register_async_signal_handler_oneshot(SIGTERM
, handle_signal
);
85 auto cmd_args
= argv_to_vec(argc
, argv
);
87 Messenger
*msgr
= Messenger::create_client_messenger(g_ceph_context
, "client");
88 msgr
->set_default_policy(Messenger::Policy::lossy_client(0));
91 ceph::async::io_context_pool
ctxpool(1);
92 MonClient
monc(MonClient(g_ceph_context
, ctxpool
));
93 int r
= monc
.build_initial_monmap();
95 cerr
<< "failed to generate initial monmap" << std::endl
;
96 goto cleanup_messenger
;
101 mirror
= new cephfs::mirror::Mirror(g_ceph_context
, cmd_args
, &monc
, msgr
);
102 r
= mirror
->init(reason
);
104 std::cerr
<< "failed to initialize cephfs-mirror: " << reason
<< std::endl
;
118 unregister_async_signal_handler(SIGHUP
, handle_signal
);
119 unregister_async_signal_handler(SIGINT
, handle_signal
);
120 unregister_async_signal_handler(SIGTERM
, handle_signal
);
121 shutdown_async_signal_handler();
123 return forker
.signal_exit(r
);