Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Handle SIGTERM and gracefully shut-down.

Kishore Nallan928b5602de92
diff --git a/TODO.md b/TODO.md
index 4437c18c..db07025b 100644
--- a/TODO.md
+++ b/TODO.md
@@ -95,7 +95,7 @@
- ~~Replica server should fail when pointed to "old" master~~
- ~~gzip compress responses~~
- ~~Have a LOG(ERROR) level~~
-- Handle SIGTERM which is sent when process is killed
+- ~~Handle SIGTERM which is sent when process is killed~~
- Parameterize replica's MAX_UPDATES_TO_SEND
- NOT operator support
- > INT32_MAX validation for float field
diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cpp
index 731e1bd1..8a2fcfb7 100644
--- a/src/main/typesense_server.cpp
+++ b/src/main/typesense_server.cpp
@@ -64,7 +64,12 @@ void replica_server_routes() {
}
int main(int argc, char **argv) {
+ // remove SIGTERM since we handle it on our own
+ g3::overrideSetupSignals({{SIGABRT, "SIGABRT"}, {SIGFPE, "SIGFPE"},{SIGILL, "SIGILL"}, {SIGSEGV, "SIGSEGV"},});
+
+ // we can install new signal handlers only after overriding above
signal(SIGINT, catch_interrupt);
+ signal(SIGTERM, catch_interrupt);
cmdline::parser options;
options.add<std::string>("data-dir", 'd', "Directory where data will be stored.", true);