]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
7c673cae | 3 | |
f67539c2 | 4 | #include <boost/intrusive/list.hpp> |
7c673cae FG |
5 | #include "common/ceph_argparse.h" |
6 | #include "global/global_init.h" | |
7 | #include "global/signal_handler.h" | |
8 | #include "common/config.h" | |
9 | #include "common/errno.h" | |
10 | #include "common/Timer.h" | |
11fdf7f2 | 11 | #include "common/TracepointProvider.h" |
1e59de90 TL |
12 | #include "rgw_main.h" |
13 | #include "rgw_signal.h" | |
7c673cae | 14 | #include "rgw_common.h" |
1e59de90 | 15 | #include "rgw_lib.h" |
7c673cae | 16 | #include "rgw_log.h" |
7c673cae FG |
17 | |
18 | #ifdef HAVE_SYS_PRCTL_H | |
19 | #include <sys/prctl.h> | |
20 | #endif | |
21 | ||
20effc67 TL |
22 | using namespace std; |
23 | ||
1e59de90 | 24 | static constexpr auto dout_subsys = ceph_subsys_rgw; |
7c673cae FG |
25 | |
26 | static sig_t sighandler_alrm; | |
27 | ||
7c673cae FG |
28 | static void godown_alarm(int signum) |
29 | { | |
30 | _exit(0); | |
31 | } | |
32 | ||
7c673cae FG |
33 | class C_InitTimeout : public Context { |
34 | public: | |
35 | C_InitTimeout() {} | |
36 | void finish(int r) override { | |
37 | derr << "Initialization timeout, failed to initialize" << dendl; | |
38 | exit(1); | |
39 | } | |
40 | }; | |
41 | ||
42 | static int usage() | |
43 | { | |
11fdf7f2 TL |
44 | cout << "usage: radosgw [options...]" << std::endl; |
45 | cout << "options:\n"; | |
46 | cout << " --rgw-region=<region> region in which radosgw runs\n"; | |
47 | cout << " --rgw-zone=<zone> zone in which radosgw runs\n"; | |
48 | cout << " --rgw-socket-path=<path> specify a unix domain socket path\n"; | |
49 | cout << " -m monaddress[:port] connect to specified monitor\n"; | |
50 | cout << " --keyring=<path> path to radosgw keyring\n"; | |
51 | cout << " --logfile=<logfile> file to log debug output\n"; | |
52 | cout << " --debug-rgw=<log-level>/<memory-level> set radosgw debug level\n"; | |
7c673cae FG |
53 | generic_server_usage(); |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
7c673cae FG |
58 | /* |
59 | * start up the RADOS connection and then handle HTTP messages as they come in | |
60 | */ | |
1e59de90 TL |
61 | int main(int argc, char *argv[]) |
62 | { | |
63 | int r{0}; | |
64 | ||
7c673cae FG |
65 | // dout() messages will be sent to stderr, but FCGX wants messages on stdout |
66 | // Redirect stderr to stdout. | |
67 | TEMP_FAILURE_RETRY(close(STDERR_FILENO)); | |
68 | if (TEMP_FAILURE_RETRY(dup2(STDOUT_FILENO, STDERR_FILENO)) < 0) { | |
69 | int err = errno; | |
70 | cout << "failed to redirect stderr to stdout: " << cpp_strerror(err) | |
71 | << std::endl; | |
72 | return ENOSYS; | |
73 | } | |
74 | ||
75 | /* alternative default for module */ | |
1e59de90 | 76 | map<std::string,std::string> defaults = { |
11fdf7f2 TL |
77 | { "debug_rgw", "1/5" }, |
78 | { "keyring", "$rgw_data/keyring" }, | |
20effc67 TL |
79 | { "objecter_inflight_ops", "24576" }, |
80 | // require a secure mon connection by default | |
81 | { "ms_mon_client_mode", "secure" }, | |
82 | { "auth_client_required", "cephx" } | |
11fdf7f2 | 83 | }; |
7c673cae | 84 | |
20effc67 | 85 | auto args = argv_to_vec(argc, argv); |
11fdf7f2 TL |
86 | if (args.empty()) { |
87 | cerr << argv[0] << ": -h or --help for usage" << std::endl; | |
88 | exit(1); | |
89 | } | |
90 | if (ceph_argparse_need_usage(args)) { | |
91 | usage(); | |
92 | exit(0); | |
93 | } | |
7c673cae | 94 | |
7c673cae | 95 | int flags = CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS; |
1911f103 TL |
96 | // Prevent global_init() from dropping permissions until frontends can bind |
97 | // privileged ports | |
98 | flags |= CINIT_FLAG_DEFER_DROP_PRIVILEGES; | |
99 | ||
1e59de90 TL |
100 | auto cct = rgw_global_init(&defaults, args, CEPH_ENTITY_TYPE_CLIENT, |
101 | CODE_ENVIRONMENT_DAEMON, flags); | |
7c673cae | 102 | |
1e59de90 TL |
103 | DoutPrefix dp(cct.get(), dout_subsys, "rgw main: "); |
104 | rgw::AppMain main(&dp); | |
7c673cae | 105 | |
1e59de90 TL |
106 | main.init_frontends1(false /* nfs */); |
107 | main.init_numa(); | |
7c673cae | 108 | |
11fdf7f2 | 109 | if (g_conf()->daemonize) { |
7c673cae FG |
110 | global_init_daemonize(g_ceph_context); |
111 | } | |
9f95a23c | 112 | ceph::mutex mutex = ceph::make_mutex("main"); |
7c673cae FG |
113 | SafeTimer init_timer(g_ceph_context, mutex); |
114 | init_timer.init(); | |
9f95a23c | 115 | mutex.lock(); |
11fdf7f2 | 116 | init_timer.add_event_after(g_conf()->rgw_init_timeout, new C_InitTimeout); |
9f95a23c | 117 | mutex.unlock(); |
7c673cae | 118 | |
7c673cae | 119 | common_init_finish(g_ceph_context); |
11fdf7f2 | 120 | init_async_signal_handler(); |
11fdf7f2 | 121 | |
1e59de90 TL |
122 | /* XXXX check locations thru sighandler_alrm */ |
123 | register_async_signal_handler(SIGHUP, rgw::signal::sighup_handler); | |
124 | r = rgw::signal::signal_fd_init(); | |
7c673cae | 125 | if (r < 0) { |
1e59de90 TL |
126 | derr << "ERROR: unable to initialize signal fds" << dendl; |
127 | exit(1); | |
20effc67 | 128 | } |
20effc67 | 129 | |
1e59de90 TL |
130 | register_async_signal_handler(SIGTERM, rgw::signal::handle_sigterm); |
131 | register_async_signal_handler(SIGINT, rgw::signal::handle_sigterm); | |
132 | register_async_signal_handler(SIGUSR1, rgw::signal::handle_sigterm); | |
133 | sighandler_alrm = signal(SIGALRM, godown_alarm); | |
20effc67 | 134 | |
1e59de90 TL |
135 | main.init_perfcounters(); |
136 | main.init_http_clients(); | |
7c673cae | 137 | |
1e59de90 TL |
138 | main.init_storage(); |
139 | if (! main.get_driver()) { | |
9f95a23c | 140 | mutex.lock(); |
7c673cae FG |
141 | init_timer.cancel_all_events(); |
142 | init_timer.shutdown(); | |
9f95a23c | 143 | mutex.unlock(); |
7c673cae FG |
144 | |
145 | derr << "Couldn't init storage provider (RADOS)" << dendl; | |
146 | return EIO; | |
147 | } | |
7c673cae | 148 | |
1e59de90 | 149 | main.cond_init_apis(); |
7c673cae | 150 | |
9f95a23c | 151 | mutex.lock(); |
7c673cae FG |
152 | init_timer.cancel_all_events(); |
153 | init_timer.shutdown(); | |
9f95a23c | 154 | mutex.unlock(); |
7c673cae | 155 | |
1e59de90 TL |
156 | main.init_ldap(); |
157 | main.init_opslog(); | |
158 | main.init_tracepoints(); | |
159 | main.init_lua(); | |
160 | main.init_frontends2(nullptr /* RGWLib */); | |
161 | main.init_notification_endpoints(); | |
7c673cae FG |
162 | |
163 | #if defined(HAVE_SYS_PRCTL_H) | |
164 | if (prctl(PR_SET_DUMPABLE, 1) == -1) { | |
165 | cerr << "warning: unable to set dumpable flag: " << cpp_strerror(errno) << std::endl; | |
166 | } | |
167 | #endif | |
168 | ||
1e59de90 | 169 | rgw::signal::wait_shutdown(); |
7c673cae FG |
170 | |
171 | derr << "shutting down" << dendl; | |
172 | ||
1e59de90 TL |
173 | const auto finalize_async_signals = []() { |
174 | unregister_async_signal_handler(SIGHUP, rgw::signal::sighup_handler); | |
175 | unregister_async_signal_handler(SIGTERM, rgw::signal::handle_sigterm); | |
176 | unregister_async_signal_handler(SIGINT, rgw::signal::handle_sigterm); | |
177 | unregister_async_signal_handler(SIGUSR1, rgw::signal::handle_sigterm); | |
178 | shutdown_async_signal_handler(); | |
179 | }; | |
7c673cae | 180 | |
1e59de90 | 181 | main.shutdown(finalize_async_signals); |
7c673cae FG |
182 | |
183 | dout(1) << "final shutdown" << dendl; | |
184 | ||
1e59de90 | 185 | rgw::signal::signal_fd_finalize(); |
7c673cae FG |
186 | |
187 | return 0; | |
1e59de90 | 188 | } /* main(int argc, char* argv[]) */ |