1
0
Fork 0

re-enabled signal handlers

This commit is contained in:
jsteemann 2017-05-05 13:09:59 +02:00
parent d2385960e4
commit edeeef8b56
5 changed files with 55 additions and 34 deletions

View File

@ -155,22 +155,10 @@ void ServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
}
void ServerFeature::start() {
if (_operationMode != OperationMode::MODE_CONSOLE) {
auto scheduler =
ApplicationServer::getFeature<SchedulerFeature>("Scheduler");
scheduler->buildControlCHandler();
}
waitForHeartbeat();
*_result = EXIT_SUCCESS;
// flush all log output before we go on... this is sensible because any
// of the following options may print or prompt, and pending log entries
// might overwrite that
Logger::flush();
switch (_operationMode) {
case OperationMode::MODE_UNITTESTS:
case OperationMode::MODE_SCRIPT:
@ -181,6 +169,19 @@ void ServerFeature::start() {
LOG_TOPIC(TRACE, Logger::STARTUP) << "server operation mode: SERVER";
break;
}
// flush all log output before we go on... this is sensible because any
// of the following options may print or prompt, and pending log entries
// might overwrite that
Logger::flush();
if (!isConsoleMode()) {
// install CTRL-C handlers
server()->registerStartupCallback([]() {
ApplicationServer::getFeature<SchedulerFeature>("Scheduler")->buildControlCHandler();
});
}
}
void ServerFeature::beginShutdown() {

View File

@ -59,6 +59,10 @@ class ServerFeature final : public application_features::ApplicationFeature {
std::vector<std::string> const& scripts() const { return _scripts; }
std::vector<std::string> const& unitTests() const { return _unitTests; }
uint32_t const& vppMaxSize() const { return _vppMaxSize; }
bool isConsoleMode() const {
return (_operationMode == OperationMode::MODE_CONSOLE);
}
private:
void waitForHeartbeat();

View File

@ -279,6 +279,18 @@ void SchedulerFeature::buildControlCHandler() {
}
#else
#ifndef WIN32
// Signal masking on POSIX platforms
//
// POSIX allows signals to be blocked using functions such as sigprocmask()
// and pthread_sigmask(). For signals to be delivered, programs must ensure
// that any signals registered using signal_set objects are unblocked in at
// least one thread.
sigset_t all;
sigemptyset(&all);
pthread_sigmask(SIG_SETMASK, &all, 0);
#endif
auto ioService = _scheduler->managerService();
_exitSignals = std::make_shared<boost::asio::signal_set>(*ioService, SIGINT,
SIGTERM, SIGQUIT);

View File

@ -384,35 +384,27 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
// first insert all features, even the inactive ones
std::vector<ApplicationFeature*> features;
for (auto& it : _features) {
auto const& us = it.second;
auto insertPosition = features.end();
if (!features.empty()) {
for (size_t i = features.size(); i > 0; --i) {
if (it.second->doesStartBefore(features[i - 1]->name())) {
for (size_t i = features.size(); i > 0; --i) {
auto const& other = features[i - 1];
if (us->doesStartBefore(other->name())) {
// we start before the other feature. so move ourselves up
insertPosition = features.begin() + (i - 1);
} else if (other->doesStartBefore(us->name())) {
// the other feature starts before us. so stop moving up
break;
} else {
// no dependencies between the two features
if (us->name() < other->name()) {
insertPosition = features.begin() + (i - 1);
}
}
}
features.insert(insertPosition, it.second);
}
for (size_t i = 1; i < features.size(); ++i) {
auto feature = features[i];
size_t insert = i;
for (size_t j = i; j > 0; --j) {
if (features[j - 1]->doesStartBefore(feature->name())) {
break;
}
insert = j - 1;
}
if (insert != i) {
for (size_t j = i; j > insert; --j) {
features[j] = features[j - 1];
}
features[insert] = feature;
}
}
LOG_TOPIC(TRACE, Logger::STARTUP) << "ordered features:";
int position = 0;
@ -425,7 +417,7 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
}
LOG_TOPIC(TRACE, Logger::STARTUP)
<< "feature #" << ++position << ": " << feature->name()
<< (feature->isEnabled() ? "" : " (disabled)") << " " << dependencies;
<< (feature->isEnabled() ? "" : " (disabled)") << dependencies;
}
// remove all inactive features
@ -605,6 +597,10 @@ void ApplicationServer::start() {
THROW_ARANGO_EXCEPTION_MESSAGE(res, std::string("startup aborted: ") + TRI_errno_string(res));
}
}
for (auto const& callback : _startupCallbacks) {
callback();
}
}
void ApplicationServer::stop() {
@ -701,3 +697,4 @@ void ApplicationServer::reportFeatureProgress(ServerState state,
reporter._feature(state, name);
}
}

View File

@ -220,6 +220,10 @@ class ApplicationServer {
static ApplicationFeature* lookupFeature(std::string const&);
char const* getBinaryPath() { return _binaryPath;}
void registerStartupCallback(std::function<void()> const& callback) {
_startupCallbacks.emplace_back(callback);
}
private:
// throws an exception that a requested feature was not found
@ -305,6 +309,9 @@ class ApplicationServer {
// reporter for progress
std::vector<ProgressHandler> _progressReports;
// callbacks that are called after start
std::vector<std::function<void()>> _startupCallbacks;
// help section displayed
std::string _helpSection;