main.cpp 3.2 KB
Newer Older
Q
qinzuoyan 已提交
1 2 3 4 5 6 7
// Copyright (c) 2017, Xiaomi, Inc.  All rights reserved.
// This source code is licensed under the Apache License Version 2.0, which
// can be found in the LICENSE file in the root directory of this source tree.

#include "pegasus_server_impl.h"
#include "pegasus_service_app.h"
#include "info_collector_app.h"
8
#include "brief_stat.h"
Q
qinzuoyan 已提交
9

10 11
#include <dsn/version.h>
#include <dsn/git_commit.h>
Q
qinzuoyan 已提交
12 13
#include <pegasus/version.h>
#include <pegasus/git_commit.h>
14

Q
qinzuoyan 已提交
15
#include <dsn/tool_api.h>
16
#include <dsn/tool-api/command_manager.h>
Q
qinzuoyan 已提交
17

18 19 20
#include <dsn/dist/replication/replication_service_app.h>
#include <dsn/dist/replication/meta_service_app.h>

Q
qinzuoyan 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <cstdio>
#include <cstring>
#include <chrono>

#include <sys/types.h>
#include <unistd.h>

#define STR_I(var) #var
#define STR(var) STR_I(var)
#ifndef DSN_BUILD_TYPE
#define PEGASUS_BUILD_TYPE ""
#else
#define PEGASUS_BUILD_TYPE STR(DSN_BUILD_TYPE)
#endif

36 37 38 39 40 41 42 43 44 45 46 47 48 49
static char const rcsid[] =
    "$Version: Pegasus Server " PEGASUS_VERSION " (" PEGASUS_GIT_COMMIT ")"
#if defined(DSN_BUILD_TYPE)
    " " STR(DSN_BUILD_TYPE)
#endif
        ", built with rDSN " DSN_CORE_VERSION " (" DSN_GIT_COMMIT ")"
        ", built by gcc " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
#if defined(DSN_BUILD_HOSTNAME)
            ", built on " STR(DSN_BUILD_HOSTNAME)
#endif
                ", built at " __DATE__ " " __TIME__ " $";

const char *pegasus_server_rcsid() { return rcsid; }

50 51 52
using namespace dsn;
using namespace dsn::replication;

Q
qinzuoyan 已提交
53 54
void dsn_app_registration_pegasus()
{
55
    dsn::service::meta_service_app::register_components();
56 57 58
    service_app::register_factory<pegasus::server::pegasus_meta_service_app>("meta");
    service_app::register_factory<pegasus::server::pegasus_replication_service_app>("replica");
    service_app::register_factory<pegasus::server::info_collector_app>("collector");
59
    pegasus::server::pegasus_server_impl::register_service();
Q
qinzuoyan 已提交
60

61
    dsn::command_manager::instance().register_command(
62
        {"server-info"},
Q
qinzuoyan 已提交
63 64 65 66 67 68 69 70 71 72
        "server-info - query server information",
        "server-info",
        [](const std::vector<std::string> &args) {
            char str[100];
            ::dsn::utils::time_ms_to_date_time(dsn_runtime_init_time_ms(), str, 100);
            std::ostringstream oss;
            oss << "Pegasus Server " << PEGASUS_VERSION << " (" << PEGASUS_GIT_COMMIT << ") "
                << PEGASUS_BUILD_TYPE << ", Started at " << str;
            return oss.str();
        });
73 74 75 76 77
    dsn::command_manager::instance().register_command(
        {"server-stat"},
        "server-stat - query selected perf counters",
        "server-stat",
        [](const std::vector<std::string> &args) { return pegasus::get_brief_stat(); });
Q
qinzuoyan 已提交
78 79 80 81 82 83 84 85 86 87 88
}

int main(int argc, char **argv)
{
    for (int i = 1; i < argc; ++i) {
        if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "-version") == 0 ||
            strcmp(argv[i], "--version") == 0) {
            printf("Pegasus Server %s (%s) %s\n",
                   PEGASUS_VERSION,
                   PEGASUS_GIT_COMMIT,
                   PEGASUS_BUILD_TYPE);
C
cailiuyang 已提交
89
            dsn_exit(0);
Q
qinzuoyan 已提交
90 91 92 93 94
        }
    }
    ddebug("pegasus server starting, pid(%d), version(%s)", (int)getpid(), pegasus_server_rcsid());
    dsn_app_registration_pegasus();
    dsn_run(argc, argv, true);
95

Q
qinzuoyan 已提交
96 97
    return 0;
}