]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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() { | |
f91f0fd5 | 17 | std::cout << "usage: ceph-immutable-object-cache [options...]" << std::endl; |
9f95a23c TL |
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) { | |
20effc67 | 34 | auto args = argv_to_vec(argc, argv); |
9f95a23c | 35 | env_to_vec(args); |
9f95a23c TL |
36 | |
37 | if (ceph_argparse_need_usage(args)) { | |
38 | usage(); | |
39 | exit(0); | |
40 | } | |
41 | ||
42 | auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT, | |
43 | CODE_ENVIRONMENT_DAEMON, | |
44 | CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); | |
45 | ||
46 | if (g_conf()->daemonize) { | |
47 | global_init_daemonize(g_ceph_context); | |
48 | } | |
49 | ||
50 | common_init_finish(g_ceph_context); | |
51 | global_init_chdir(g_ceph_context); | |
52 | ||
53 | init_async_signal_handler(); | |
54 | register_async_signal_handler(SIGHUP, sighup_handler); | |
55 | register_async_signal_handler_oneshot(SIGINT, handle_signal); | |
56 | register_async_signal_handler_oneshot(SIGTERM, handle_signal); | |
57 | ||
20effc67 TL |
58 | auto cmd_args = argv_to_vec(argc, argv); |
59 | ||
9f95a23c TL |
60 | |
61 | cachectl = new ceph::immutable_obj_cache::CacheController(g_ceph_context, | |
62 | cmd_args); | |
63 | int r = cachectl->init(); | |
64 | if (r < 0) { | |
65 | std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl; | |
66 | goto cleanup; | |
67 | } | |
68 | ||
f6b5b4d7 TL |
69 | r = cachectl->run(); |
70 | if (r < 0) { | |
71 | goto cleanup; | |
72 | } | |
9f95a23c TL |
73 | |
74 | cleanup: | |
75 | unregister_async_signal_handler(SIGHUP, sighup_handler); | |
76 | unregister_async_signal_handler(SIGINT, handle_signal); | |
77 | unregister_async_signal_handler(SIGTERM, handle_signal); | |
78 | shutdown_async_signal_handler(); | |
79 | ||
80 | delete cachectl; | |
81 | ||
82 | return r < 0 ? EXIT_SUCCESS : EXIT_FAILURE; | |
83 | } |