Improve info and error messages shown in boot sequence.

Also, if the data directory does not exist, say so without crashing.
This commit is contained in:
Kishore Nallan 2017-12-21 07:35:32 +05:30
parent 01275c38f2
commit a84a0a55bc
4 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -0,0 +1 @@
#define TYPESENSE_VERSION "0.6.1"

View File

@ -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);

View File

@ -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(