|
12 | 12 | #include "fboss/platform/platform_manager/ConfigUtils.h" |
13 | 13 | #include "fboss/platform/platform_manager/PkgManager.h" |
14 | 14 | #include "fboss/platform/platform_manager/PlatformManagerHandler.h" |
| 15 | +#include "fboss/platform/platform_manager/ScubaLogger.h" |
15 | 16 |
|
16 | 17 | using namespace facebook; |
17 | 18 | using namespace facebook::fboss::platform; |
@@ -49,54 +50,67 @@ int main(int argc, char** argv) { |
49 | 50 | fb303::registerFollyLoggingOptionHandlers(); |
50 | 51 | helpers::init(&argc, &argv); |
51 | 52 |
|
52 | | - auto config = ConfigUtils().getConfig(); |
| 53 | + try { |
| 54 | + auto config = ConfigUtils().getConfig(); |
| 55 | + |
| 56 | + PkgManager pkgManager(config); |
| 57 | + pkgManager.processAll(); |
| 58 | + PlatformExplorer platformExplorer(config); |
| 59 | + platformExplorer.explore(); |
| 60 | + if (FLAGS_run_once) { |
| 61 | + XLOG(INFO) << fmt::format( |
| 62 | + "Ran with --run_once={}. Skipping running as a daemon...", |
| 63 | + FLAGS_run_once); |
| 64 | + return 0; |
| 65 | + } |
53 | 66 |
|
54 | | - PkgManager pkgManager(config); |
55 | | - pkgManager.processAll(); |
56 | | - PlatformExplorer platformExplorer(config); |
57 | | - platformExplorer.explore(); |
58 | | - if (FLAGS_run_once) { |
59 | | - XLOG(INFO) << fmt::format( |
60 | | - "Ran with --run_once={}. Skipping running as a daemon...", |
61 | | - FLAGS_run_once); |
62 | | - return 0; |
63 | | - } |
| 67 | + // When systemd starts PlatformManager, it sets the below env in PM |
| 68 | + // environment. This is a path to Unix domain socket at /run/systemd/notify. |
| 69 | + if (!FLAGS_run_in_netos) { |
| 70 | + const auto notifySocketEnv{"NOTIFY_SOCKET"}; |
| 71 | + if (std::getenv(notifySocketEnv)) { |
| 72 | + sdNotifyReady(); |
| 73 | + } else { |
| 74 | + XLOG(WARNING) << fmt::format( |
| 75 | + "Skipping sd_notify since ${} is not set which does not " |
| 76 | + "imply systemd execution.", |
| 77 | + notifySocketEnv); |
| 78 | + } |
| 79 | + } |
64 | 80 |
|
65 | | - // When systemd starts PlatformManager, it sets the below env in PM |
66 | | - // environment. This is a path to Unix domain socket at /run/systemd/notify. |
67 | | - if (!FLAGS_run_in_netos) { |
68 | | - const auto notifySocketEnv{"NOTIFY_SOCKET"}; |
69 | | - if (std::getenv(notifySocketEnv)) { |
70 | | - sdNotifyReady(); |
71 | | - } else { |
72 | | - XLOG(WARNING) << fmt::format( |
73 | | - "Skipping sd_notify since ${} is not set which does not " |
74 | | - "imply systemd execution.", |
75 | | - notifySocketEnv); |
| 81 | + std::optional<DataStore> ds = platformExplorer.getDataStore(); |
| 82 | + if (!ds.has_value()) { |
| 83 | + XLOG(ERR) |
| 84 | + << "PlatformExplorer did not succeed. Not starting Thrift Service."; |
| 85 | + return 1; |
76 | 86 | } |
77 | | - } |
| 87 | + XLOG(INFO) << "Running PlatformManager thrift service..."; |
78 | 88 |
|
79 | | - std::optional<DataStore> ds = platformExplorer.getDataStore(); |
80 | | - if (!ds.has_value()) { |
81 | | - XLOG(ERR) |
82 | | - << "PlatformExplorer did not succeed. Not starting Thrift Service."; |
83 | | - return 1; |
84 | | - } |
85 | | - XLOG(INFO) << "Running PlatformManager thrift service..."; |
| 89 | + auto server = std::make_shared<apache::thrift::ThriftServer>(); |
| 90 | + auto handler = std::make_shared<PlatformManagerHandler>( |
| 91 | + platformExplorer, ds.value(), config); |
| 92 | + server->setPort(FLAGS_thrift_port); |
| 93 | + server->setInterface(handler); |
| 94 | + server->setAllowPlaintextOnLoopback(true); |
| 95 | + |
| 96 | + auto evb = server->getEventBaseManager()->getEventBase(); |
| 97 | + helpers::SignalHandler signalHandler(evb, server); |
86 | 98 |
|
87 | | - auto server = std::make_shared<apache::thrift::ThriftServer>(); |
88 | | - auto handler = std::make_shared<PlatformManagerHandler>( |
89 | | - platformExplorer, ds.value(), config); |
90 | | - server->setPort(FLAGS_thrift_port); |
91 | | - server->setInterface(handler); |
92 | | - server->setAllowPlaintextOnLoopback(true); |
| 99 | + helpers::runThriftService( |
| 100 | + server, handler, "PlatformManagerService", FLAGS_thrift_port); |
93 | 101 |
|
94 | | - auto evb = server->getEventBaseManager()->getEventBase(); |
95 | | - helpers::SignalHandler signalHandler(evb, server); |
| 102 | + XLOG(INFO) << "================ STOPPED PLATFORM BINARY ================"; |
| 103 | + return 0; |
| 104 | + } catch (const std::exception& ex) { |
| 105 | + // Log unexpected crash to Scuba |
| 106 | + std::unordered_map<std::string, std::string> normals; |
96 | 107 |
|
97 | | - helpers::runThriftService( |
98 | | - server, handler, "PlatformManagerService", FLAGS_thrift_port); |
| 108 | + normals["event"] = "unexpected_crash"; |
| 109 | + normals["error_message"] = ex.what(); |
99 | 110 |
|
100 | | - XLOG(INFO) << "================ STOPPED PLATFORM BINARY ================"; |
101 | | - return 0; |
| 111 | + ScubaLogger::log(normals); |
| 112 | + XLOG(FATAL) << "Platform Manager crashed with unexpected exception: " |
| 113 | + << ex.what(); |
| 114 | + return 1; |
| 115 | + } |
102 | 116 | } |
0 commit comments