main.cpp 3.1 KB
Newer Older
1 2
/**
 *  @file
D
Daniel Larimer 已提交
3
 *  @copyright defined in eosio/LICENSE.txt
4
 */
N
Nathan Hourt 已提交
5 6
#include <appbase/application.hpp>

D
Daniel Larimer 已提交
7 8
#include <eosio/chain_plugin/chain_plugin.hpp>
#include <eosio/http_plugin/http_plugin.hpp>
9
#include <eosio/net_plugin/net_plugin.hpp>
10
#include <eosio/producer_plugin/producer_plugin.hpp>
11
#include <eosio/txn_test_gen_plugin/txn_test_gen_plugin.hpp>
N
Nathan Hourt 已提交
12 13

#include <fc/log/logger_config.hpp>
14
#include <fc/log/appender.hpp>
N
Nathan Hourt 已提交
15 16
#include <fc/exception/exception.hpp>

17
#include <boost/dll/runtime_symbol_info.hpp>
N
Nathan Hourt 已提交
18 19
#include <boost/exception/diagnostic_information.hpp>

20 21
#include "config.hpp"

N
Nathan Hourt 已提交
22
using namespace appbase;
P
Pravin 已提交
23
using namespace eosio;
N
Nathan Hourt 已提交
24

25 26 27 28
namespace fc {
   std::unordered_map<std::string,appender::ptr>& get_appender_map();
}

J
Jonathan Giszczak 已提交
29 30 31 32
namespace detail {

void configure_logging(const bfs::path& config_path)
{
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
   try {
      try {
         fc::configure_logging(config_path);
      } catch (...) {
         elog("Error reloading logging.json");
         throw;
      }
   } catch (const fc::exception& e) {
      elog("${e}", ("e",e.to_detail_string()));
   } catch (const boost::exception& e) {
      elog("${e}", ("e",boost::diagnostic_information(e)));
   } catch (const std::exception& e) {
      elog("${e}", ("e",e.what()));
   } catch (...) {
      // empty
   }
J
Jonathan Giszczak 已提交
49 50 51 52
}

} // namespace detail

53 54
void logging_conf_loop()
{
55 56 57 58 59 60 61 62 63 64 65 66 67
   std::shared_ptr<boost::asio::signal_set> sighup_set(new boost::asio::signal_set(app().get_io_service(), SIGHUP));
   sighup_set->async_wait([sighup_set](const boost::system::error_code& err, int /*num*/) {
      if(!err)
      {
         ilog("Received HUP.  Reloading logging configuration.");
         auto config_path = app().get_logging_conf();
         if(fc::exists(config_path))
            ::detail::configure_logging(config_path);
         for(auto iter : fc::get_appender_map())
            iter.second->initialize(app().get_io_service());
         logging_conf_loop();
      }
   });
68 69
}

70 71
void initialize_logging()
{
72 73 74 75 76 77 78 79
   auto config_path = app().get_logging_conf();
   if(fc::exists(config_path))
     fc::configure_logging(config_path); // intentionally allowing exceptions to escape
   for(auto iter : fc::get_appender_map())
     iter.second->initialize(app().get_io_service());

   logging_conf_loop();
}
80

N
Nathan Hourt 已提交
81 82 83
int main(int argc, char** argv)
{
   try {
84
      app().set_version(eosio::nodeos::config::version);
85 86 87 88
      auto root = fc::app_path(); 
      app().set_default_data_dir(root / "eosio/nodeos/data" );
      app().set_default_config_dir(root / "eosio/nodeos/config" );
      if(!app().initialize<chain_plugin, http_plugin, net_plugin, txn_test_gen_plugin, producer_plugin>(argc, argv))
N
Nathan Hourt 已提交
89
         return -1;
90
      initialize_logging();
91
      ilog("nodeos version ${ver}", ("ver", eosio::nodeos::config::itoh(static_cast<uint32_t>(app().version()))));
92
      ilog("eosio root is ${root}", ("root", root.string()));
N
Nathan Hourt 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105
      app().startup();
      app().exec();
   } catch (const fc::exception& e) {
      elog("${e}", ("e",e.to_detail_string()));
   } catch (const boost::exception& e) {
      elog("${e}", ("e",boost::diagnostic_information(e)));
   } catch (const std::exception& e) {
      elog("${e}", ("e",e.what()));
   } catch (...) {
      elog("unknown exception");
   }
   return 0;
}