Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
2
9
10#include <fc/log/logger.hpp>
12#include <fc/log/appender.hpp>
14
15#include <boost/dll/runtime_symbol_info.hpp>
16#include <boost/exception/diagnostic_information.hpp>
17
18#include "config.hpp"
19
20using namespace appbase;
21using namespace sysio;
22
23namespace detail {
24
26 config.appenders.push_back(
27 fc::appender_config( "deep-mind", "dmlog" )
28 );
29
31 dmlc.name = "deep-mind";
33 dmlc.enabled = true;
34 dmlc.appenders.push_back("deep-mind");
35
36 config.loggers.push_back( dmlc );
37
38 return config;
39}
40
41void configure_logging(const bfs::path& config_path)
42{
43 try {
44 try {
45 if( fc::exists( config_path ) ) {
46 fc::configure_logging( config_path );
47 } else {
49
51 }
52 } catch (...) {
53 elog("Error reloading logging.json");
54 throw;
55 }
56 } catch (const fc::exception& e) {
57 elog("${e}", ("e",e.to_detail_string()));
58 } catch (const boost::exception& e) {
59 elog("${e}", ("e",boost::diagnostic_information(e)));
60 } catch (const std::exception& e) {
61 elog("${e}", ("e",e.what()));
62 } catch (...) {
63 // empty
64 }
65}
66
67} // namespace detail
68
70{
71 auto config_path = app().get_logging_conf();
72 if( fc::exists( config_path ) ) {
73 ilog( "Received HUP. Reloading logging configuration from ${p}.", ("p", config_path.string()) );
74 } else {
75 ilog( "Received HUP. No log config found at ${p}, setting to default.", ("p", config_path.string()) );
76 }
77 ::detail::configure_logging( config_path );
78 fc::log_config::initialize_appenders( app().get_io_service() );
79}
80
82{
83 auto config_path = app().get_logging_conf();
84 if(fc::exists(config_path))
85 fc::configure_logging(config_path); // intentionally allowing exceptions to escape
86 else {
88
90 }
91
92 fc::log_config::initialize_appenders( app().get_io_service() );
93
95}
96
107
108int main(int argc, char** argv)
109{
110 try {
111 app().set_version(sysio::nodeop::config::version);
114
115 auto root = fc::app_path();
116 app().set_default_data_dir(root / "sysio" / nodeop::config::node_executable_name / "data" );
117 app().set_default_config_dir(root / "sysio" / nodeop::config::node_executable_name / "config" );
119 .default_unix_socket_path = "",
120 .default_http_port = 8888
121 });
122 if(!app().initialize<chain_plugin, net_plugin, producer_plugin, resource_monitor_plugin>(argc, argv)) {
123 const auto& opts = app().get_options();
124 if( opts.count("help") || opts.count("version") || opts.count("full-version") || opts.count("print-default-config") ) {
125 return SUCCESS;
126 }
127 return INITIALIZE_FAIL;
128 }
129 if (auto resmon_plugin = app().find_plugin<resource_monitor_plugin>()) {
130 resmon_plugin->monitor_directory(app().data_dir());
131 } else {
132 elog("resource_monitor_plugin failed to initialize");
133 return INITIALIZE_FAIL;
134 }
136 ilog( "${name} version ${ver} ${fv}",
137 ("name", nodeop::config::node_executable_name)("ver", app().version_string())
138 ("fv", app().version_string() == app().full_version_string() ? "" : app().full_version_string()) );
139 ilog("${name} using configuration file ${c}", ("name", nodeop::config::node_executable_name)("c", app().full_config_file_path().string()));
140 ilog("${name} data directory is ${d}", ("name", nodeop::config::node_executable_name)("d", app().data_dir().string()));
141 app().startup();
143 app().exec();
144 } catch( const extract_genesis_state_exception& e ) {
145 return EXTRACTED_GENESIS;
146 } catch( const fixed_reversible_db_exception& e ) {
147 return FIXED_REVERSIBLE;
148 } catch( const node_management_success& e ) {
150 } catch( const fc::exception& e ) {
151 if( e.code() == fc::std_exception_code ) {
152 if( e.top_message().find( "atabase dirty flag set" ) != std::string::npos ) {
153 elog( "database dirty flag set (likely due to unclean shutdown): replay required" );
154 return DATABASE_DIRTY;
155 }
156 }
157 elog( "${e}", ("e", e.to_detail_string()));
158 return OTHER_FAIL;
159 } catch( const boost::interprocess::bad_alloc& e ) {
160 elog("bad alloc");
161 return BAD_ALLOC;
162 } catch( const boost::exception& e ) {
163 elog("${e}", ("e",boost::diagnostic_information(e)));
164 return OTHER_FAIL;
165 } catch( const std::runtime_error& e ) {
166 if( std::string(e.what()).find("atabase dirty flag set") != std::string::npos ) {
167 elog( "database dirty flag set (likely due to unclean shutdown): replay required" );
168 return DATABASE_DIRTY;
169 } else {
170 elog( "${e}", ("e",e.what()));
171 }
172 return OTHER_FAIL;
173 } catch( const std::exception& e ) {
174 elog("${e}", ("e",e.what()));
175 return OTHER_FAIL;
176 } catch( ... ) {
177 elog("unknown exception");
178 return OTHER_FAIL;
179 }
180
181 ilog("${name} successfully exiting", ("name", nodeop::config::node_executable_name));
182 return SUCCESS;
183}
const bpo::variables_map & get_options() const
void set_version_string(std::string v)
User provided version string for version_string() which overrides git describe value.
void set_version(uint64_t version)
Set version.
void set_default_config_dir(const bfs::path &config_dir="etc")
Set default config directory.
void set_sighup_callback(std::function< void()> callback)
Set function pointer invoked on receipt of SIGHUP.
bfs::path get_logging_conf() const
Get logging configuration path.
void set_full_version_string(std::string v)
User provided full version string for full_version_string()
void set_default_data_dir(const bfs::path &data_dir="data-dir")
Set default data directory.
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
const char * what() const noexcept override
static void set_defaults(const http_plugin_defaults config)
Defines exception's used by fc.
char ** argv
#define ilog(FORMAT,...)
Definition logger.hpp:118
#define elog(FORMAT,...)
Definition logger.hpp:130
application & app()
fc::logging_config & add_deep_mind_logger(fc::logging_config &config)
Definition main.cpp:25
void configure_logging(const bfs::path &config_path)
Definition main.cpp:41
const path & app_path()
bool exists(const path &p)
@ std_exception_code
Definition exception.hpp:32
void configure_logging(const fc::path &log_config)
const std::string & version_client()
< Grab the basic version information of the client; example: v1.8.0-rc1
Definition version.cpp:5
const std::string & version_full()
Definition version.cpp:10
void initialize_logging()
Definition main.cpp:81
return_codes
Definition main.cpp:97
@ FIXED_REVERSIBLE
Definition main.cpp:103
@ INITIALIZE_FAIL
Definition main.cpp:99
@ DATABASE_DIRTY
Definition main.cpp:102
@ NODE_MANAGEMENT_SUCCESS
Definition main.cpp:105
@ BAD_ALLOC
Definition main.cpp:101
@ EXTRACTED_GENESIS
Definition main.cpp:104
@ OTHER_FAIL
Definition main.cpp:98
@ SUCCESS
Definition main.cpp:100
void logging_conf_handler()
Definition main.cpp:69
static void initialize_appenders(boost::asio::io_service &ios)
std::vector< string > appenders
std::optional< log_level > level
if not set, then parents level is used.
static logging_config default_config()