summaryrefslogtreecommitdiff
path: root/src/ingestor.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-19 12:33:48 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-19 12:33:48 +0000
commit8c6fecd356003309f8eebec30374344272ca6072 (patch)
tree023f79e07a3abd0829c91bfffd5d2a5657d8a225 /src/ingestor.cpp
parentee01cb7017e3895419544a0385f90f8eb0498680 (diff)
downloadwebstat-8c6fecd356003309f8eebec30374344272ca6072.tar.bz2
webstat-8c6fecd356003309f8eebec30374344272ca6072.tar.xz
webstat-8c6fecd356003309f8eebec30374344272ca6072.zip
Gracefully handle SIGTERM
Apache sends SIGTERM to the logger process to it shutdown. Honestly I thought it would just close stdin and I should have checked.
Diffstat (limited to 'src/ingestor.cpp')
-rw-r--r--src/ingestor.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp
index def3ce1..e2018ad 100644
--- a/src/ingestor.cpp
+++ b/src/ingestor.cpp
@@ -3,6 +3,7 @@
#include "uaLookup.hpp"
#include "util.hpp"
#include <connection.h>
+#include <csignal>
#include <dbTypes.h>
#include <fstream>
#include <modifycommand.h>
@@ -64,8 +65,11 @@ namespace WebStat {
return std::make_tuple(std::get<N>(ENTITY_TYPE_MAP)(std::get<N>(values))...);
}(std::make_index_sequence<VALUE_COUNT>());
}
+
}
+ Ingestor * Ingestor::currentIngestor = nullptr;
+
Ingestor::Ingestor(const utsname & host, IngestorSettings settings) :
Ingestor {host,
std::make_shared<DB::ConnectionPool>(
@@ -84,6 +88,31 @@ namespace WebStat {
bindMany(ins, 0, hostnameId, host.nodename, host.sysname, host.release, host.version, host.machine,
host.domainname);
ins->execute();
+
+ assert(!currentIngestor);
+ currentIngestor = this;
+ signal(SIGTERM, &sigtermHandler);
+ }
+
+ Ingestor::~Ingestor()
+ {
+ assert(currentIngestor);
+ signal(SIGTERM, SIG_DFL);
+ currentIngestor = nullptr;
+ }
+
+ void
+ Ingestor::sigtermHandler(int sigNo)
+ {
+ assert(currentIngestor);
+ currentIngestor->terminate(sigNo);
+ }
+
+ void
+ Ingestor::terminate(int)
+ {
+ terminated = true;
+ curl_multi_wakeup(curl.get());
}
Ingestor::ScanResult
@@ -138,7 +167,7 @@ namespace WebStat {
const auto curlTimeOut = static_cast<int>(
std::chrono::duration_cast<std::chrono::milliseconds>(settings.checkJobsAfter).count());
- while (curl_multi_poll(curl.get(), &logIn, 1, curlTimeOut, nullptr) == CURLM_OK) {
+ while (!terminated && curl_multi_poll(curl.get(), &logIn, 1, curlTimeOut, nullptr) == CURLM_OK) {
if (logIn.revents) {
if (auto line = scn::scan<std::string>(input, "{:[^\n]}\n")) {
linesRead++;