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 20

INITIALIZE_EASYLOGGINGPP
G
groot 已提交
21 22 23

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

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

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

G
groot 已提交
31
    signal(SIGINT, server::SignalUtil::HandleSignal);
G
groot 已提交
32 33 34 35 36 37
    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 已提交
38
                                           {"log_conf_file", required_argument, 0, 'l'},
G
groot 已提交
39 40 41 42 43 44 45 46 47
                                           {"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 已提交
48
    std::string config_filename, log_config_file;
G
groot 已提交
49 50 51 52
    std::string pid_filename;

    app_name = argv[0];

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

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

            case 'p': {
                char *pid_filename_ptr = strdup(optarg);
                pid_filename = pid_filename_ptr;
                free(pid_filename_ptr);
G
groot 已提交
81
                std::cout << pid_filename << std::endl;
G
groot 已提交
82 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;
        }
    }

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

void
print_help(const std::string &app_name) {
G
groot 已提交
107 108 109 110 111 112 113
    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 已提交
114
}