OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
archiverd.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "controller.hpp"
8
9#include <csignal>
10#include <iostream>
11
12// LCOV_EXCL_START
13auto main(int argc, char** argv) -> int {
14 auto args = cbdc::config::get_args(argc, argv);
15
16 if(args.size() < 3) {
17 std::cerr << "Usage: " << args[0]
18 << " <config file> <archiver id> [<max samples>]"
19 << std::endl;
20 return 0;
21 }
22
23 size_t max_samples{0};
24 if(args.size() > 3) {
25 max_samples = static_cast<size_t>(std::stoull(args[3]));
26 }
27
28 auto cfg_or_err = cbdc::config::load_options(args[1]);
29 if(std::holds_alternative<std::string>(cfg_or_err)) {
30 std::cerr << "Error loading config file: "
31 << std::get<std::string>(cfg_or_err) << std::endl;
32 return -1;
33 }
34 auto opts = std::get<cbdc::config::options>(cfg_or_err);
35
36 const auto archiver_id = std::stoull(args[2]);
37
38 if(opts.m_archiver_endpoints.size() <= archiver_id) {
39 std::cerr << "Archiver ID not in config file" << std::endl;
40 return -1;
41 }
42
43 auto logger = std::make_shared<cbdc::logging::log>(
44 opts.m_archiver_loglevels[archiver_id]);
45
46 auto ctl = cbdc::archiver::controller(static_cast<uint32_t>(archiver_id),
47 opts,
48 logger,
49 max_samples);
50
51 if(!ctl.init()) {
52 return -1;
53 }
54
55 // Can't capture variables in lambda for sighandler.
56 // Have to make this static instead.
57 static std::atomic_bool running{true};
58
59 // Wait for CTRL+C etc
60 std::signal(SIGINT, [](int /* signal */) {
61 running = false;
62 });
63
64 logger->info("Archiver running...");
65
66 while(running && ctl.running()) {
67 static constexpr auto running_check_delay
68 = std::chrono::milliseconds(1000);
69 std::this_thread::sleep_for(running_check_delay);
70 }
71
72 logger->info("Shutting down...");
73
74 return 0;
75}
76// LCOV_EXCL_STOP
auto main(int argc, char **argv) -> int
Definition archiverd.cpp:13
Wrapper for the archiver executable implementation.
auto load_options(const std::string &config_file) -> std::variant< options, std::string >
Loads options from the given config file and check for invariants.
Definition config.cpp:668
auto get_args(int argc, char **argv) -> std::vector< std::string >
Converts c-args from an executable's main function into a vector of strings.
Definition config.cpp:751