| 724 | } |
| 725 | |
| 726 | std::tuple<bool, std::string> |
| 727 | initialize_jsonrpc_server() |
| 728 | { |
| 729 | std::tuple<bool, std::string> ok{true, {}}; |
| 730 | auto filePath = RecConfigReadConfigPath("proxy.config.jsonrpc.filename", ts::filename::JSONRPC); |
| 731 | |
| 732 | auto serverConfig = rpc::config::RPCConfig{}; |
| 733 | serverConfig.load_from_file(filePath); |
| 734 | if (!serverConfig.is_enabled()) { |
| 735 | Dbg(dbg_ctl_rpc_init, "JSONRPC Disabled"); |
| 736 | return ok; |
| 737 | } |
| 738 | |
| 739 | // create and start the server. |
| 740 | try { |
| 741 | jsonrpcServer = new rpc::RPCServer{serverConfig}; |
| 742 | jsonrpcServer->start_thread(TSThreadInit, TSThreadDestroy); |
| 743 | } catch (std::exception const &ex) { |
| 744 | // Only the constructor throws, so if we are here there should be no |
| 745 | // jsonrpcServer object. |
| 746 | ink_assert(jsonrpcServer == nullptr); |
| 747 | std::string msg; |
| 748 | return {false, swoc::bwprint(msg, "Server failed: '{}'", ex.what())}; |
| 749 | } |
| 750 | // Register admin handlers. |
| 751 | rpc::admin::register_admin_jsonrpc_handlers(); |
| 752 | Dbg(dbg_ctl_rpc_init, "JSONRPC. Public admin handlers registered."); |
| 753 | |
| 754 | return ok; |
| 755 | } |
| 756 | |
| 757 | #define CMD_ERROR -2 // serious error, exit maintenance mode |
| 758 | #define CMD_FAILED -1 // error, but recoverable |
no test coverage detected