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
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "common/ceph_argparse.h"
#include "common/config.h"
#include "common/debug.h"
#include "common/errno.h"
#include "global/global_init.h"
#include "global/signal_handler.h"
#include "CacheController.h"
#include <vector>
ceph::immutable_obj_cache::CacheController *cachectl = nullptr;
void usage() {
std::cout << "usage: ceph-immutable-object-cache [options...]" << std::endl;
std::cout << "options:\n";
std::cout << " -m monaddress[:port] connect to specified monitor\n";
std::cout << " --keyring=<path> path to keyring for local "
<< "cluster\n";
std::cout << " --log-file=<logfile> file to log debug output\n";
std::cout << " --debug-immutable-obj-cache=<log-level>/<memory-level> "
<< "set debug level\n";
generic_server_usage();
}
static void handle_signal(int signum) {
if (cachectl)
cachectl->handle_signal(signum);
}
int main(int argc, const char **argv) {
std::vector<const char*> args;
env_to_vec(args);
argv_to_vec(argc, argv, args);
if (ceph_argparse_need_usage(args)) {
usage();
exit(0);
}
auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT,
CODE_ENVIRONMENT_DAEMON,
CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
if (g_conf()->daemonize) {
global_init_daemonize(g_ceph_context);
}
common_init_finish(g_ceph_context);
global_init_chdir(g_ceph_context);
init_async_signal_handler();
register_async_signal_handler(SIGHUP, sighup_handler);
register_async_signal_handler_oneshot(SIGINT, handle_signal);
register_async_signal_handler_oneshot(SIGTERM, handle_signal);
std::vector<const char*> cmd_args;
argv_to_vec(argc, argv, cmd_args);
cachectl = new ceph::immutable_obj_cache::CacheController(g_ceph_context,
cmd_args);
int r = cachectl->init();
if (r < 0) {
std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl;
goto cleanup;
}
r = cachectl->run();
if (r < 0) {
goto cleanup;
}
cleanup:
unregister_async_signal_handler(SIGHUP, sighup_handler);
unregister_async_signal_handler(SIGINT, handle_signal);
unregister_async_signal_handler(SIGTERM, handle_signal);
shutdown_async_signal_handler();
delete cachectl;
return r < 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
|