Skip to content

Commit

Permalink
Print version as kvrocks in kvrocks2redis (apache#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored and p1u3o committed Aug 15, 2023
1 parent 4346130 commit a665142
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void InitGoogleLog(const Config *config) {
FLAGS_max_log_size = 100;
FLAGS_logbufsecs = 0;

if (util::ToLower(config->log_dir) == "stdout") {
if (util::EqualICase(config->log_dir, "stdout")) {
for (int level = google::INFO; level <= google::FATAL; level++) {
google::SetLogDestination(level, "");
}
Expand Down Expand Up @@ -218,7 +218,7 @@ bool SupervisedSystemd() {

auto fd = UniqueFD(socket(AF_UNIX, SOCK_DGRAM, 0));
if (!fd) {
LOG(WARNING) << "Can't connect to systemd socket " << notify_socket;
LOG(WARNING) << "Cannot connect to systemd socket " << notify_socket;
return false;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ bool SupervisedSystemd() {
sendto_flags |= MSG_NOSIGNAL;
#endif
if (sendmsg(*fd, &hdr, sendto_flags) < 0) {
LOG(WARNING) << "Can't send notification to systemd";
LOG(WARNING) << "Cannot send notification to systemd";
return false;
}
return true;
Expand Down
37 changes: 26 additions & 11 deletions utils/kvrocks2redis/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,49 @@ std::function<void()> hup_handler;

struct Options {
std::string conf_file = kDefaultConfPath;
bool show_usage = false;
};

std::ostream &PrintVersion(std::ostream &os) {
os << "kvrocks2redis ";

if (VERSION != "unstable") {
os << "version ";
}

os << VERSION;

if (!GIT_COMMIT.empty()) {
os << " (commit " << GIT_COMMIT << ")";
}

return os;
}

extern "C" void SignalHandler(int sig) {
if (hup_handler) hup_handler();
}

static void Usage(const char *program) {
std::cout << program << " sync kvrocks to redis\n"
<< "\t-c config file, default is " << kDefaultConfPath << "\n"
<< "\t-h help\n";
<< "\t-c <path> specifies the config file, defaulting to " << kDefaultConfPath << "\n"
<< "\t-h print this help message\n"
<< "\t-v print version information\n";
exit(0);
}

static Options ParseCommandLineOptions(int argc, char **argv) {
int ch = 0;
Options opts;
while ((ch = ::getopt(argc, argv, "c:h")) != -1) {
while ((ch = ::getopt(argc, argv, "c:hv")) != -1) {
switch (ch) {
case 'c': {
opts.conf_file = optarg;
break;
}
case 'h': {
opts.show_usage = true;
break;
}
case 'v':
std::cout << PrintVersion << std::endl;
exit(0);
case 'h':
default:
Usage(argv[0]);
}
Expand Down Expand Up @@ -130,9 +146,7 @@ int main(int argc, char *argv[]) {
signal(SIGINT, SignalHandler);
signal(SIGTERM, SignalHandler);

std::cout << "Version: " << VERSION << " @" << GIT_COMMIT << std::endl;
auto opts = ParseCommandLineOptions(argc, argv);
if (opts.show_usage) Usage(argv[0]);
std::string config_file_path = std::move(opts.conf_file);

kvrocks2redis::Config config;
Expand All @@ -143,6 +157,7 @@ int main(int argc, char *argv[]) {
}

InitGoogleLog(&config);
LOG(INFO) << PrintVersion;

if (config.daemonize) Daemonize();

Expand All @@ -168,7 +183,7 @@ int main(int argc, char *argv[]) {
Parser parser(&storage, &writer);

Sync sync(&storage, &writer, &parser, &config);
hup_handler = [&sync]() {
hup_handler = [&sync] {
if (!sync.IsStopped()) {
LOG(INFO) << "Bye Bye";
sync.Stop();
Expand Down

0 comments on commit a665142

Please sign in to comment.