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

Improve info and error messages shown in boot sequence.

Kishore Nallana84a0a55bce6
diff --git a/TODO.md b/TODO.md
index c86207f1..74aecf53 100644
--- a/TODO.md
+++ b/TODO.md
@@ -78,6 +78,7 @@
- ~~Export collection~~
- ~~get collection should show schema~~
- ~~API key should be allowed as a GET parameter also (for JSONP)~~
+- ~~Don't crash when the data directory is not found~~
- handle hyphens (replace them)
- clean special chars before indexing
- NOT operator support
diff --git a/include/typesense_version.h b/include/typesense_version.h
new file mode 100644
index 00000000..6a35bff3
--- /dev/null
+++ b/include/typesense_version.h
@@ -0,0 +1 @@
+#define TYPESENSE_VERSION "0.6.1"
\ No newline at end of file
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 277511b6..6bd9bd46 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -99,6 +99,8 @@ int HttpServer::create_listener(void) {
setup_ssl(ssl_cert_path.c_str(), ssl_cert_key_path.c_str());
}
+ ctx.globalconf->server_name = h2o_strdup(NULL, "", SIZE_MAX);
+
accept_ctx->ctx = &ctx;
accept_ctx->hosts = config.hosts;
@@ -114,7 +116,6 @@ int HttpServer::create_listener(void) {
return -1;
}
- ctx.globalconf->server_name = h2o_strdup(NULL, "", SIZE_MAX);
listener_socket = h2o_evloop_socket_create(ctx.loop, fd, H2O_SOCKET_FLAG_DONT_READ);
listener_socket->data = this;
h2o_socket_read_start(listener_socket, on_accept);
@@ -131,9 +132,11 @@ int HttpServer::run() {
h2o_multithread_register_receiver(message_queue, message_receiver, on_message);
if (create_listener() != 0) {
- std::cerr << "Failed to listen on " << listen_address << ":" << listen_port << std::endl
- << "Error: " << strerror(errno) << std::endl;
+ std::cerr << "Failed to listen on " << listen_address << ":" << listen_port << " - "
+ << strerror(errno) << std::endl;
return 1;
+ } else {
+ std::cout << "Server has started. Ready to accept requests on port " << listen_port << std::endl;
}
on(STOP_SERVER_MESSAGE, HttpServer::on_stop_server);
diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cpp
index eda0e0b0..6f678339 100644
--- a/src/main/typesense_server.cpp
+++ b/src/main/typesense_server.cpp
@@ -3,11 +3,14 @@
#include <vector>
#include <string>
#include <thread>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <cmdline.h>
#include "http_server.h"
#include "api.h"
#include "string_utils.h"
#include "replicator.h"
+#include "typesense_version.h"
HttpServer* server;
@@ -17,6 +20,11 @@ void catch_interrupt(int sig) {
server->stop();
}
+bool directory_exists(const std::string & dir_path) {
+ struct stat info;
+ return stat(dir_path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);
+}
+
int main(int argc, char **argv) {
cmdline::parser options;
options.add<std::string>("data-dir", 'd', "Directory where data will be stored.", true);
@@ -35,16 +43,25 @@ int main(int argc, char **argv) {
signal(SIGINT, catch_interrupt);
+ std::cout << "Typesense version " << TYPESENSE_VERSION << std::endl;
+
+ if(!directory_exists(options.get<std::string>("data-dir"))) {
+ std::cerr << "Typesense failed to start. " << "Data directory " << options.get<std::string>("data-dir")
+ << " does not exist." << std::endl;
+ return 1;
+ }
+
Store store(options.get<std::string>("data-dir"));
CollectionManager & collectionManager = CollectionManager::get_instance();
Option<bool> init_op = collectionManager.init(&store, options.get<std::string>("api-key"),
options.get<std::string>("search-only-api-key"));
if(init_op.ok()) {
- std::cout << "Finished restoring all collections from disk." << std::endl;
+ std::cout << "Finished loading collections from disk." << std::endl;
} else {
- std::cerr << "Failed initializing collections from store..." << std::endl;
- std::cerr << init_op.error() << std::endl;
+ std::cerr << "Typesense failed to start. " << "Could not load collections from disk: "
+ << init_op.error() << std::endl;
+ return 1;
}
server = new HttpServer(