]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/immutable_object_cache/main.cc
bfe49df6323894fce40afe5cb801a040dc543c9b
[ceph.git] / ceph / src / tools / immutable_object_cache / 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 "CacheController.h"
11
12 #include <vector>
13
14 ceph::immutable_obj_cache::CacheController *cachectl = nullptr;
15
16 void usage() {
17 std::cout << "usage: cache controller [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 "
21 << "cluster\n";
22 std::cout << " --log-file=<logfile> file to log debug output\n";
23 std::cout << " --debug-immutable-obj-cache=<log-level>/<memory-level> "
24 << "set debug level\n";
25 generic_server_usage();
26 }
27
28 static void handle_signal(int signum) {
29 if (cachectl)
30 cachectl->handle_signal(signum);
31 }
32
33 int main(int argc, const char **argv) {
34 std::vector<const char*> args;
35 env_to_vec(args);
36 argv_to_vec(argc, argv, args);
37
38 if (ceph_argparse_need_usage(args)) {
39 usage();
40 exit(0);
41 }
42
43 auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT,
44 CODE_ENVIRONMENT_DAEMON,
45 CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
46
47 if (g_conf()->daemonize) {
48 global_init_daemonize(g_ceph_context);
49 }
50
51 common_init_finish(g_ceph_context);
52 global_init_chdir(g_ceph_context);
53
54 init_async_signal_handler();
55 register_async_signal_handler(SIGHUP, sighup_handler);
56 register_async_signal_handler_oneshot(SIGINT, handle_signal);
57 register_async_signal_handler_oneshot(SIGTERM, handle_signal);
58
59 std::vector<const char*> cmd_args;
60 argv_to_vec(argc, argv, cmd_args);
61
62 cachectl = new ceph::immutable_obj_cache::CacheController(g_ceph_context,
63 cmd_args);
64 int r = cachectl->init();
65 if (r < 0) {
66 std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl;
67 goto cleanup;
68 }
69
70 cachectl->run();
71
72 cleanup:
73 unregister_async_signal_handler(SIGHUP, sighup_handler);
74 unregister_async_signal_handler(SIGINT, handle_signal);
75 unregister_async_signal_handler(SIGTERM, handle_signal);
76 shutdown_async_signal_handler();
77
78 delete cachectl;
79
80 return r < 0 ? EXIT_SUCCESS : EXIT_FAILURE;
81 }