1
0
Fork 0
forked from lthn/blockchain

Initialize and manage API server lifecycle in daemon

This commit is contained in:
snider 2025-10-15 20:59:05 +01:00
parent 3a2ccb55c6
commit 073f3db1aa

View file

@ -18,9 +18,12 @@
// node.cpp : Defines the entry point for the console application.
//
#include "ApiServer.hpp"
#include "include_base_utils.h"
#include "version.h"
#include "oatpp/core/base/Environment.hpp"
using namespace epee;
#include <boost/program_options.hpp>
@ -464,18 +467,31 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Stratum server started ok");
}
tools::signal_handler::install([&dch, &p2psrv, &stratum_server_ptr] {
dch.stop_handling();
// Initialize API server
oatpp::base::Environment::init();
ApiServer api_server;
api_server.start();
// Setup signal handler to gracefully stop the main p2p loop
tools::signal_handler::install([&p2psrv] {
LOG_PRINT_L0("SIGINT received, stopping p2p net loop...");
p2psrv.send_stop_signal();
if (stratum_server_ptr)
stratum_server_ptr->send_stop_signal();
});
LOG_PRINT_L0("Starting p2p net loop...");
p2psrv.run();
LOG_PRINT_L0("p2p net loop stopped");
p2psrv.run(); // This blocks until the stop signal is received
LOG_PRINT_L0("p2p net loop stopped. Starting shutdown...");
//stop components
// Shutdown sequence
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 thread joined.");
//stop other components
if (stratum_enabled)
{
LOG_PRINT_L0("Stopping stratum server...");
@ -506,6 +522,10 @@ 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.");
ccore.set_critical_error_handler(nullptr);
ccore.set_currency_protocol(NULL);
cprotocol.set_p2p_endpoint(NULL);