diff options
Diffstat (limited to 'configd/src')
-rw-r--r-- | configd/src/apps/sentinel/config-handler.cpp | 5 | ||||
-rw-r--r-- | configd/src/apps/sentinel/service.cpp | 29 | ||||
-rw-r--r-- | configd/src/apps/sentinel/service.h | 2 |
3 files changed, 22 insertions, 14 deletions
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp index d4600471904..15560daf435 100644 --- a/configd/src/apps/sentinel/config-handler.cpp +++ b/configd/src/apps/sentinel/config-handler.cpp @@ -59,6 +59,11 @@ ConfigHandler::terminateServices(bool catchable, bool printDebug) { for (const auto & entry : _services) { Service *service = entry.second.get(); + service->setAutomatic(false); + service->prepare_for_shutdown(); + } + for (const auto & entry : _services) { + Service *service = entry.second.get(); if (printDebug && service->isRunning()) { LOG(info, "%s: killing", service->name().c_str()); } diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp index fa5af578946..9c78894f1a7 100644 --- a/configd/src/apps/sentinel/service.cpp +++ b/configd/src/apps/sentinel/service.cpp @@ -87,14 +87,26 @@ Service::~Service() delete _config; } +void +Service::prepare_for_shutdown() +{ + auto cmd = _config->preShutdownCommand; + if (cmd.empty()) { + return; + } + if (_state == RUNNING) { + // only run this once, before signaling the service: + LOG(info, "prepare %s for shutdown: running %s", name().c_str(), cmd.c_str()); + runCommand(cmd); + } else { + LOG(info, "%s: not running, skipping preShutdownCommand(%s)", name().c_str(), cmd.c_str()); + } +} + int Service::terminate(bool catchable, bool dumpState) { if (isRunning()) { - if (_state == RUNNING) { - // only run this once, before signaling the service: - runPreShutdownCommand(); - } LOG(debug, "%s: terminate(%s)", name().c_str(), catchable ? "cleanly" : "NOW"); resetRestartPenalty(); kill(_pid, SIGCONT); // if it was stopped for some reason @@ -135,15 +147,6 @@ Service::terminate(bool catchable, bool dumpState) } void -Service::runPreShutdownCommand() -{ - if (_config->preShutdownCommand.length() > 0) { - LOG(debug, "%s: runPreShutdownCommand(%s)", name().c_str(), _config->preShutdownCommand.c_str()); - runCommand(_config->preShutdownCommand); - } -} - -void Service::runCommand(const std::string & command) { int ret = system(command.c_str()); diff --git a/configd/src/apps/sentinel/service.h b/configd/src/apps/sentinel/service.h index 03d0e5f0473..8ef9893a014 100644 --- a/configd/src/apps/sentinel/service.h +++ b/configd/src/apps/sentinel/service.h @@ -34,7 +34,6 @@ private: void runChild() __attribute__((noreturn)); void setState(ServiceState state); - void runPreShutdownCommand(); void runCommand(const std::string & command); const char *stateName(ServiceState state) const; @@ -52,6 +51,7 @@ public: StartMetrics &metrics); void reconfigure(const SentinelConfig::Service& config); int pid() const { return _pid; } + void prepare_for_shutdown(); int terminate(bool catchable, bool dumpState); int terminate() { return terminate(true, false); |