| | |
| | | #include "box.h" |
| | | #include "center.h" |
| | | #include "defs.h" |
| | | #include "log.h" |
| | | #include "signalhandle.h" |
| | | #include <boost/interprocess/sync/named_mutex.hpp> |
| | | #include <chrono> |
| | |
| | | if (mtx && time_stamp) { |
| | | Guard lock(*mtx); |
| | | auto now = NowSec(); |
| | | // printf("old: %ld, now: %ld\n", *time_stamp, now); |
| | | LOG_DEBUG() << "old: " << *time_stamp << ", now: " << now; |
| | | if (now > *time_stamp + 10) { |
| | | *time_stamp = now; |
| | | auto UpdateTime = [this, time_stamp]() { |
| | |
| | | return 0; |
| | | } |
| | | |
| | | ns_log::AddLog("/tmp/bhshmq_center.log", true, true); |
| | | auto lvl = args.Get("log", "info"); |
| | | if (strcasecmp(lvl.c_str(), "trace") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::trace); } |
| | | if (strcasecmp(lvl.c_str(), "debug") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::debug); } |
| | | if (strcasecmp(lvl.c_str(), "info") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::info); } |
| | | if (strcasecmp(lvl.c_str(), "warning") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::warning); } |
| | | if (strcasecmp(lvl.c_str(), "error") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::error); } |
| | | if (strcasecmp(lvl.c_str(), "fatal") == 0) { ns_log::ResetLogLevel(ns_log::LogLevel::fatal); } |
| | | |
| | | auto &shm = BHomeShm(); |
| | | GlobalInit(shm); |
| | | |
| | | InstanceFlag inst(shm, kCenterRunningFlag); |
| | | if (!inst.TryStartAsFirstInstance()) { |
| | | printf("another instance is running, exit.\n"); |
| | | LOG_INFO() << "another instance is running, exit."; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | BHCenter center(shm); |
| | | center.Start(); |
| | | |
| | | printf("center started ...\n"); |
| | | LOG_INFO() << "center started ..."; |
| | | WaitForSignals({SIGINT, SIGTERM}); |
| | | center.Stop(); |
| | | LOG_INFO() << "center stopped."; |
| | | return 0; |
| | | } |
| | | |