main.cpp 4.1 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
G
groot 已提交
6
#include "server/Server.h"
7
#include "version.h"
J
jinhai 已提交
8

G
groot 已提交
9 10 11 12 13
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include <signal.h>
G
groot 已提交
14
#include <easylogging++.h>
Y
yu yunfeng 已提交
15
#include "metrics/Metrics.h"
G
groot 已提交
16 17 18

#include "utils/SignalUtil.h"
#include "utils/CommonUtil.h"
G
groot 已提交
19
#include "utils/LogUtil.h"
G
groot 已提交
20 21

INITIALIZE_EASYLOGGINGPP
G
groot 已提交
22 23 24

void print_help(const std::string &app_name);

J
jinhai 已提交
25
using namespace zilliz::milvus;
G
groot 已提交
26 27 28

int
main(int argc, char *argv[]) {
G
groot 已提交
29 30
    std::cout << std::endl << "Welcome to use Milvus by Zillz!" << std::endl;
    std::cout << "Milvus " << BUILD_TYPE << " version: v" << MILVUS_VERSION << " built at " << BUILD_TIME << std::endl;
G
groot 已提交
31

G
groot 已提交
32
    signal(SIGINT, server::SignalUtil::HandleSignal);
G
groot 已提交
33 34 35 36 37 38
    signal(SIGSEGV, server::SignalUtil::HandleSignal);
    signal(SIGUSR1, server::SignalUtil::HandleSignal);
    signal(SIGUSR2, server::SignalUtil::HandleSignal);

    std::string app_name = basename(argv[0]);
    static struct option long_options[] = {{"conf_file", required_argument, 0, 'c'},
G
groot 已提交
39
                                           {"log_conf_file", required_argument, 0, 'l'},
G
groot 已提交
40 41 42 43 44 45 46 47 48
                                           {"help", no_argument, 0, 'h'},
                                           {"daemon", no_argument, 0, 'd'},
                                           {"pid_file", required_argument, 0, 'p'},
                                           {NULL, 0, 0, 0}};

    int option_index = 0;
    int64_t start_daemonized = 0;
//    int pid_fd;

G
groot 已提交
49
    std::string config_filename, log_config_file;
G
groot 已提交
50 51 52 53
    std::string pid_filename;

    app_name = argv[0];

G
groot 已提交
54 55
    if(argc < 2) {
        print_help(app_name);
G
groot 已提交
56
        std::cout << "Milvus server exit..." << std::endl;
G
groot 已提交
57 58
        return EXIT_FAILURE;
    }
G
groot 已提交
59 60

    int value;
G
groot 已提交
61
    while ((value = getopt_long(argc, argv, "c:l:p:dh", long_options, &option_index)) != -1) {
G
groot 已提交
62 63 64 65 66
        switch (value) {
            case 'c': {
                char *config_filename_ptr = strdup(optarg);
                config_filename = config_filename_ptr;
                free(config_filename_ptr);
G
groot 已提交
67
                std::cout << "Loading configuration from: " << config_filename << std::endl;
G
groot 已提交
68 69
                break;
            }
G
groot 已提交
70 71 72 73
            case 'l': {
                char *log_filename_ptr = strdup(optarg);
                log_config_file = log_filename_ptr;
                free(log_filename_ptr);
G
groot 已提交
74
                std::cout << "Initial log config from: " << log_config_file << std::endl;
G
groot 已提交
75 76
                break;
            }
G
groot 已提交
77 78 79 80 81

            case 'p': {
                char *pid_filename_ptr = strdup(optarg);
                pid_filename = pid_filename_ptr;
                free(pid_filename_ptr);
G
groot 已提交
82
                std::cout << pid_filename << std::endl;
G
groot 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                break;
            }

            case 'd':
                start_daemonized = 1;
                break;
            case 'h':
                print_help(app_name);
                return EXIT_SUCCESS;
            case '?':
                print_help(app_name);
                return EXIT_FAILURE;
            default:
                print_help(app_name);
                break;
        }
    }

J
jinhai 已提交
101
    zilliz::milvus::server::InitLog(log_config_file);
G
groot 已提交
102

G
groot 已提交
103 104 105 106 107 108 109
    server::Server* server_ptr = server::Server::Instance();
    server_ptr->Init(start_daemonized, pid_filename, config_filename);
    return server_ptr->Start();
}

void
print_help(const std::string &app_name) {
G
groot 已提交
110 111 112 113 114 115 116
    std::cout << std::endl<< "Usage: " << app_name << " [OPTIONS]" << std::endl << std::endl;
    std::cout << "  Options:" << std::endl;
    std::cout << "   -h --help                 Print this help" << std::endl;
    std::cout << "   -c --conf_file filename   Read configuration from the file" << std::endl;
    std::cout << "   -d --daemon               Daemonize this application" << std::endl;
    std::cout << "   -p --pid_file  filename   PID file used by daemonized app" << std::endl;
    std::cout << std::endl;
G
groot 已提交
117
}