Files
scylladb/core/app-template.hh
Nadav Har'El fcce304908 collectd: Don't use the network stack before it is set up
The current code (this will change soon with my reactor patches)
constructs a default (Posix) network stack before reactore::configure()
reassigns it to the requested network stack.

It turns out there is one place we use the network stack before calling
reactore::configure(), which ends up using the Posix stack even though
we want the native stack - this is both silly and plainly doesn't work on
the OSv setup.

The problem is that app_template.hh tries to configure scollectd before
the engine is started. This calls scollectd::impl::start() which calls
engine.net().make_udp_channel(). When this happens this early, it creates
a Posix socket...

This patch moves the scollectd configuration to after the engine is
started. It makes sense to me: As far as I understand, scollectd is all
about sending packets (diagnostic packets), and it's kind of silly to
start sending packets before starting the machinary which allows us to
send packets.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
[avi: use customary indentation, remove unneeded make_ready_future()]
2014-11-09 17:46:09 +02:00

70 lines
2.0 KiB
C++

/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#ifndef _APP_TEMPLATE_HH
#define _APP_TEMPLATE_HH
#include <boost/program_options.hpp>
#include <fstream>
#include <cstdlib>
#include "core/reactor.hh"
#include "core/scollectd.hh"
namespace bpo = boost::program_options;
class app_template {
private:
bpo::options_description _opts;
boost::optional<bpo::variables_map> _configuration;
public:
app_template() : _opts("App options") {
_opts.add_options()
("help", "show help message")
;
_opts.add(reactor::get_options_description());
_opts.add(smp::get_options_description());
_opts.add(scollectd::get_options_description());
};
boost::program_options::options_description_easy_init add_options() {
return _opts.add_options();
}
bpo::variables_map& configuration() { return *_configuration; }
template<typename Func>
int run(int ac, char ** av, Func&& func) {
bpo::variables_map configuration;
bpo::store(bpo::command_line_parser(ac, av).options(_opts).run(), configuration);
auto home = std::getenv("HOME");
if (home) {
std::ifstream ifs(std::string(home) + "/.config/seastar/seastar.conf");
if (ifs) {
bpo::store(bpo::parse_config_file(ifs, _opts), configuration);
}
}
bpo::notify(configuration);
if (configuration.count("help")) {
std::cout << _opts << "\n";
return 1;
}
smp::configure(configuration);
_configuration = {std::move(configuration)};
engine.when_started().then([this] {
scollectd::configure( this->configuration());
}).then(
func
).rescue([] (auto get_ex) {
try {
get_ex();
} catch (std::exception& ex) {
std::cout << "program failed with uncaught exception: " << ex.what() << "\n";
engine.exit(1);
}
});
return engine.run();
};
};
#endif