blob: 9079ad664c5c986e5982ba6b6c1ef42568c076a1 [file] [log] [blame]
Ed Tanous3cd70722024-04-06 09:24:01 -07001#include "webserver_run.hpp"
2
3#include "bmcweb_config.h"
4
5#include "app.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -07006#include "dbus_monitor.hpp"
7#include "dbus_singleton.hpp"
8#include "event_service_manager.hpp"
9#include "google/google_service_root.hpp"
10#include "hostname_monitor.hpp"
11#include "ibm/management_console_rest.hpp"
12#include "image_upload.hpp"
13#include "kvm_websocket.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070014#include "logging.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070015#include "login_routes.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070016#include "obmc_console.hpp"
17#include "openbmc_dbus_rest.hpp"
18#include "redfish.hpp"
19#include "redfish_aggregator.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070020#include "user_monitor.hpp"
21#include "vm_websocket.hpp"
22#include "webassets.hpp"
23
Ed Tanous3cd70722024-04-06 09:24:01 -070024#include <boost/asio/io_context.hpp>
25#include <sdbusplus/asio/connection.hpp>
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070026#include <sdbusplus/asio/object_server.hpp>
Ed Tanous5b904292024-04-16 11:10:17 -070027
28#include <memory>
Ed Tanous3cd70722024-04-06 09:24:01 -070029
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070030static void setLogLevel(const std::string& logLevel)
31{
32 const std::basic_string_view<char>* iter =
33 std::ranges::find(crow::mapLogLevelFromName, logLevel);
34 if (iter == crow::mapLogLevelFromName.end())
35 {
36 BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
37 return;
38 }
39 crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
40 BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
41}
42
Ed Tanous3cd70722024-04-06 09:24:01 -070043int run()
44{
45 auto io = std::make_shared<boost::asio::io_context>();
46 App app(io);
47
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070048 std::shared_ptr<sdbusplus::asio::connection> systemBus =
49 std::make_shared<sdbusplus::asio::connection>(*io);
50 crow::connections::systemBus = systemBus.get();
51
52 auto server = sdbusplus::asio::object_server(systemBus);
53
54 std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
55 server.add_interface("/xyz/openbmc_project/bmcweb",
56 "xyz.openbmc_project.bmcweb");
57
58 iface->register_method("SetLogLevel", setLogLevel);
59
60 iface->initialize();
Ed Tanous3cd70722024-04-06 09:24:01 -070061
62 // Static assets need to be initialized before Authorization, because auth
63 // needs to build the whitelist from the static routes
64
Ed Tanous25b54db2024-04-17 15:40:31 -070065 if constexpr (BMCWEB_STATIC_HOSTING)
66 {
67 crow::webassets::requestRoutes(app);
68 }
Ed Tanous3cd70722024-04-06 09:24:01 -070069
Ed Tanous25b54db2024-04-17 15:40:31 -070070 if constexpr (BMCWEB_KVM)
71 {
72 crow::obmc_kvm::requestRoutes(app);
73 }
Ed Tanous3cd70722024-04-06 09:24:01 -070074
Ed Tanous25b54db2024-04-17 15:40:31 -070075 if constexpr (BMCWEB_REDFISH)
76 {
77 redfish::RedfishService redfish(app);
Ed Tanous3cd70722024-04-06 09:24:01 -070078
Ed Tanous25b54db2024-04-17 15:40:31 -070079 // Create EventServiceManager instance and initialize Config
80 redfish::EventServiceManager::getInstance(&*io);
Ed Tanous3cd70722024-04-06 09:24:01 -070081
Ed Tanous25b54db2024-04-17 15:40:31 -070082 if constexpr (BMCWEB_REDFISH_AGGREGATION)
83 {
84 // Create RedfishAggregator instance and initialize Config
85 redfish::RedfishAggregator::getInstance(&*io);
86 }
87 }
Ed Tanous3cd70722024-04-06 09:24:01 -070088
Ed Tanous25b54db2024-04-17 15:40:31 -070089 if constexpr (BMCWEB_REST)
90 {
91 crow::dbus_monitor::requestRoutes(app);
92 crow::image_upload::requestRoutes(app);
93 crow::openbmc_mapper::requestRoutes(app);
94 }
Ed Tanous3cd70722024-04-06 09:24:01 -070095
Ed Tanous25b54db2024-04-17 15:40:31 -070096 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
97 {
98 crow::obmc_console::requestRoutes(app);
99 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700100
Ed Tanous3cd70722024-04-06 09:24:01 -0700101 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700102
Ed Tanous25b54db2024-04-17 15:40:31 -0700103 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
104 {
105 crow::ibm_mc::requestRoutes(app);
106 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700107
Ed Tanous25b54db2024-04-17 15:40:31 -0700108 if constexpr (BMCWEB_GOOGLE_API)
109 {
110 crow::google_api::requestRoutes(app);
111 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700112
Ed Tanous3cd70722024-04-06 09:24:01 -0700113 crow::login_routes::requestRoutes(app);
114
Jayaprakash Mutyalaff0a0882024-06-26 09:08:53 +0000115 if constexpr (!BMCWEB_REDFISH_DBUS_LOG)
Ed Tanous3cd70722024-04-06 09:24:01 -0700116 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700117 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
118 if (rc != 0)
119 {
120 BMCWEB_LOG_ERROR("Redfish event handler setup failed...");
121 return rc;
122 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700123 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700124
Ed Tanous25b54db2024-04-17 15:40:31 -0700125 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700126 {
127 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
128 crow::hostname_monitor::registerHostnameSignal();
129 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700130
131 bmcweb::registerUserRemovedSignal();
132
133 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700134
135 systemBus->request_name("xyz.openbmc_project.bmcweb");
136
Ed Tanous3cd70722024-04-06 09:24:01 -0700137 io->run();
138
139 crow::connections::systemBus = nullptr;
140
Ed Tanous9ed3f902024-07-15 17:54:31 -0700141 // TODO(ed) Make event log monitor an RAII object instead of global vars
142 redfish::EventServiceManager::stopEventLogMonitor();
143
Ed Tanous3cd70722024-04-06 09:24:01 -0700144 return 0;
145}