| 5220 | } |
| 5221 | |
| 5222 | void StartAPIServer() { |
| 5223 | SetupLog(); |
| 5224 | std::string real_endpoint = FLAGS_endpoint; |
| 5225 | if (real_endpoint.empty()) { |
| 5226 | GetRealEndpoint(&real_endpoint); |
| 5227 | } |
| 5228 | |
| 5229 | auto api_service = std::make_unique<::fedb::http::APIServerImpl>(); |
| 5230 | ::fedb::sdk::ClusterOptions cluster_options; |
| 5231 | cluster_options.zk_cluster = FLAGS_zk_cluster; |
| 5232 | cluster_options.zk_path = FLAGS_zk_root_path; |
| 5233 | if (!api_service->Init(cluster_options)) { |
| 5234 | PDLOG(WARNING, "Fail to init"); |
| 5235 | exit(1); |
| 5236 | } |
| 5237 | |
| 5238 | brpc::ServerOptions options; |
| 5239 | options.num_threads = FLAGS_thread_pool_size; |
| 5240 | brpc::Server server; |
| 5241 | if (server.AddService(api_service.get(), brpc::SERVER_DOESNT_OWN_SERVICE, "/* => Process") != 0) { |
| 5242 | PDLOG(WARNING, "Fail to add service"); |
| 5243 | exit(1); |
| 5244 | } |
| 5245 | |
| 5246 | if (server.Start(real_endpoint.c_str(), &options) != 0) { |
| 5247 | PDLOG(WARNING, "Fail to start server"); |
| 5248 | exit(1); |
| 5249 | } |
| 5250 | PDLOG(INFO, "start apiserver on endpoint %s with version %s", real_endpoint.c_str(), FEDB_VERSION.c_str()); |
| 5251 | server.set_version(FEDB_VERSION.c_str()); |
| 5252 | server.RunUntilAskedToQuit(); |
| 5253 | } |
| 5254 | |
| 5255 | int main(int argc, char* argv[]) { |
| 5256 | ::google::SetVersionString(FEDB_VERSION.c_str()); |