From 60df03ff1f76180793e2ca35f0ca503ddea48e00 Mon Sep 17 00:00:00 2001 From: snider Date: Thu, 16 Oct 2025 17:06:37 +0100 Subject: [PATCH] adds API server enablement option and conditional initialization in daemon --- src/daemon/daemon.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index f9214cfa..6cd8716d 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -59,6 +59,7 @@ BOOST_CLASS_VERSION(nodetool::node_server arg_rpc_server_threads("rpc-server-threads", "Specify number of RPC server threads. Default: 10", RPC_SERVER_DEFAULT_THREADS_NUM); const command_line::arg_descriptor arg_do_warp_mode("do-warp-mode", "This option pre-loads and unserialize all data into RAM and provide significant speed increase in RPC-handling, requires 32GB psychical RAM at least(64GB recommended). Might be helpful for production servers(like remote nodes or public nodes for mobile apps)."); +const command_line::arg_descriptor arg_api_enabled("api-enabled", "Enable the API server", true); namespace po = boost::program_options; @@ -187,6 +188,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, arg_rpc_server_threads); command_line::add_arg(desc_cmd_sett, arg_do_warp_mode); + command_line::add_arg(desc_cmd_sett, arg_api_enabled); arg_market_disable.default_value = true; arg_market_disable.use_default = true; @@ -468,10 +470,14 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Stratum server started ok"); } - // Initialize API server - oatpp::base::Environment::init(); - ApiServer api_server(vm, &ccore, &p2psrv, &rpc_server); - api_server.start(); + std::unique_ptr api_server; + bool api_enabled = command_line::get_arg(vm, arg_api_enabled); + if (api_enabled) { + // Initialize API server + oatpp::base::Environment::init(); + api_server = std::make_unique(vm, &ccore, &p2psrv, &rpc_server); + api_server->start(); + } // Setup signal handler to gracefully stop the main p2p loop tools::signal_handler::install([&p2psrv] { @@ -487,10 +493,12 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Stopping command handler..."); dch.stop_handling(); - LOG_PRINT_L0("Stopping API server..."); - api_server.stop(); - api_server.wait(); - LOG_PRINT_L0("API server stopped"); + if (api_server) { + LOG_PRINT_L0("Stopping API server..."); + api_server->stop(); + api_server->wait(); + LOG_PRINT_L0("API server stopped"); + } //stop other components if (stratum_enabled) @@ -523,9 +531,11 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Deinitializing p2p..."); p2psrv.deinit(); - LOG_PRINT_L0("Destroying oatpp environment..."); - oatpp::base::Environment::destroy(); - LOG_PRINT_L0("oatpp environment destroyed."); + if (api_enabled) { + LOG_PRINT_L0("Destroying oatpp environment..."); + oatpp::base::Environment::destroy(); + LOG_PRINT_L0("oatpp environment destroyed."); + } ccore.set_critical_error_handler(nullptr); ccore.set_currency_protocol(NULL);