mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
Add stop daemon command
This commit is contained in:
parent
6433e7349c
commit
f29789187a
@ -217,6 +217,15 @@ stop_mining(const std::vector<std::string>& args)
|
|||||||
return m_executor.stop_mining();
|
return m_executor.stop_mining();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T_command_executor>
|
||||||
|
bool t_command_parser_executor<T_command_executor>::
|
||||||
|
stop_daemon(const std::vector<std::string>& args)
|
||||||
|
{
|
||||||
|
if (!args.empty()) return false;
|
||||||
|
|
||||||
|
return m_executor.stop_daemon();
|
||||||
|
}
|
||||||
|
|
||||||
template class t_command_parser_executor<t_interactive_command_executor>;
|
template class t_command_parser_executor<t_interactive_command_executor>;
|
||||||
template class t_command_parser_executor<t_rpc_command_executor>;
|
template class t_command_parser_executor<t_rpc_command_executor>;
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ public:
|
|||||||
bool start_mining(const std::vector<std::string>& args);
|
bool start_mining(const std::vector<std::string>& args);
|
||||||
|
|
||||||
bool stop_mining(const std::vector<std::string>& args);
|
bool stop_mining(const std::vector<std::string>& args);
|
||||||
|
|
||||||
|
bool stop_daemon(const std::vector<std::string>& args);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace daemonize
|
} // namespace daemonize
|
||||||
|
@ -90,6 +90,11 @@ t_command_server<T_command_executor>::t_command_server(
|
|||||||
, std::bind(&t_command_parser_executor<T_command_executor>::show_difficulty, &m_parser, p::_1)
|
, std::bind(&t_command_parser_executor<T_command_executor>::show_difficulty, &m_parser, p::_1)
|
||||||
, "Show difficulty"
|
, "Show difficulty"
|
||||||
);
|
);
|
||||||
|
m_command_lookup.set_handler(
|
||||||
|
"stop_daemon"
|
||||||
|
, std::bind(&t_command_parser_executor<T_command_executor>::stop_daemon, &m_parser, p::_1)
|
||||||
|
, "Stop the daemon"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T_command_executor>
|
template <typename T_command_executor>
|
||||||
|
@ -161,3 +161,8 @@ bool t_interactive_command_executor::stop_mining() {
|
|||||||
m_srv.get_payload_object().get_core().get_miner().stop();
|
m_srv.get_payload_object().get_core().get_miner().stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool t_interactive_command_executor::stop_daemon() {
|
||||||
|
std::cout << "This is a stub! The old interactive commands should go away once testing is complete!" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -46,6 +46,8 @@ public:
|
|||||||
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads);
|
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads);
|
||||||
|
|
||||||
bool stop_mining();
|
bool stop_mining();
|
||||||
|
|
||||||
|
bool stop_daemon();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace daemonize
|
} // namespace daemonize
|
||||||
|
@ -313,6 +313,18 @@ bool t_rpc_command_executor::stop_mining() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool t_rpc_command_executor::stop_daemon()
|
||||||
|
{
|
||||||
|
cryptonote::COMMAND_RPC_STOP_DAEMON::request req;
|
||||||
|
cryptonote::COMMAND_RPC_STOP_DAEMON::response res;
|
||||||
|
|
||||||
|
if (rpc_request(req, res, "/stop_daemon", "Daemon did not stop"))
|
||||||
|
{
|
||||||
|
tools::success_msg_writer() << "Stop signal sent";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T_req, typename T_res>
|
template <typename T_req, typename T_res>
|
||||||
bool t_rpc_command_executor::json_rpc_request(
|
bool t_rpc_command_executor::json_rpc_request(
|
||||||
T_req & req
|
T_req & req
|
||||||
|
@ -57,6 +57,8 @@ public:
|
|||||||
|
|
||||||
bool stop_mining();
|
bool stop_mining();
|
||||||
|
|
||||||
|
bool stop_daemon();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T_req, typename T_res>
|
template <typename T_req, typename T_res>
|
||||||
bool json_rpc_request(
|
bool json_rpc_request(
|
||||||
|
@ -367,6 +367,7 @@ namespace cryptonote
|
|||||||
res.status = CORE_RPC_STATUS_OK;
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, connection_context& cntx)
|
bool core_rpc_server::on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, connection_context& cntx)
|
||||||
{
|
{
|
||||||
res.connections = m_p2p.get_connection_info();
|
res.connections = m_p2p.get_connection_info();
|
||||||
@ -374,6 +375,13 @@ namespace cryptonote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool core_rpc_server::on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res, connection_context& cntx)
|
||||||
|
{
|
||||||
|
m_p2p.send_stop_signal();
|
||||||
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
|
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
|
||||||
{
|
{
|
||||||
CHECK_CORE_BUSY();
|
CHECK_CORE_BUSY();
|
||||||
|
@ -51,6 +51,7 @@ namespace cryptonote
|
|||||||
MAP_URI_AUTO_JON2("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL)
|
MAP_URI_AUTO_JON2("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL)
|
||||||
MAP_URI_AUTO_JON2("/get_transaction_pool", on_get_transaction_pool, COMMAND_RPC_GET_TRANSACTION_POOL)
|
MAP_URI_AUTO_JON2("/get_transaction_pool", on_get_transaction_pool, COMMAND_RPC_GET_TRANSACTION_POOL)
|
||||||
MAP_URI_AUTO_JON2("/get_connections", on_get_connections, COMMAND_RPC_GET_CONNECTIONS)
|
MAP_URI_AUTO_JON2("/get_connections", on_get_connections, COMMAND_RPC_GET_CONNECTIONS)
|
||||||
|
MAP_URI_AUTO_JON2("/stop_daemon", on_stop_daemon, COMMAND_RPC_STOP_DAEMON)
|
||||||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||||
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
||||||
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
||||||
@ -79,6 +80,7 @@ namespace cryptonote
|
|||||||
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx);
|
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx);
|
||||||
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, connection_context& cntx);
|
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, connection_context& cntx);
|
||||||
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, connection_context& cntx);
|
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, connection_context& cntx);
|
||||||
|
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res, connection_context& cntx);
|
||||||
|
|
||||||
//json_rpc
|
//json_rpc
|
||||||
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
|
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
|
||||||
|
@ -598,5 +598,23 @@ namespace cryptonote
|
|||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct COMMAND_RPC_STOP_DAEMON
|
||||||
|
{
|
||||||
|
struct request
|
||||||
|
{
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct response
|
||||||
|
{
|
||||||
|
std::string status;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(status)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user