blob: dfed2b757f452c9fd6e379a3372142c45cddb62f [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"
Ed Tanous2185dde2024-11-22 11:33:51 -08009#include "filesystem_log_watcher.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070010#include "google/google_service_root.hpp"
11#include "hostname_monitor.hpp"
12#include "ibm/management_console_rest.hpp"
13#include "image_upload.hpp"
14#include "kvm_websocket.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070015#include "logging.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070016#include "login_routes.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070017#include "obmc_console.hpp"
18#include "openbmc_dbus_rest.hpp"
19#include "redfish.hpp"
20#include "redfish_aggregator.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070021#include "user_monitor.hpp"
22#include "vm_websocket.hpp"
23#include "webassets.hpp"
24
Ed Tanous3cd70722024-04-06 09:24:01 -070025#include <boost/asio/io_context.hpp>
26#include <sdbusplus/asio/connection.hpp>
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070027#include <sdbusplus/asio/object_server.hpp>
Ed Tanous5b904292024-04-16 11:10:17 -070028
Ed Tanous41fe81c2024-09-02 15:08:41 -070029#include <algorithm>
Ed Tanous5b904292024-04-16 11:10:17 -070030#include <memory>
Ed Tanous41fe81c2024-09-02 15:08:41 -070031#include <string>
32#include <string_view>
Ed Tanous3cd70722024-04-06 09:24:01 -070033
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070034static void setLogLevel(const std::string& logLevel)
35{
36 const std::basic_string_view<char>* iter =
37 std::ranges::find(crow::mapLogLevelFromName, logLevel);
38 if (iter == crow::mapLogLevelFromName.end())
39 {
40 BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
41 return;
42 }
43 crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
44 BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
45}
46
Ed Tanous3cd70722024-04-06 09:24:01 -070047int run()
48{
49 auto io = std::make_shared<boost::asio::io_context>();
50 App app(io);
51
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070052 std::shared_ptr<sdbusplus::asio::connection> systemBus =
53 std::make_shared<sdbusplus::asio::connection>(*io);
54 crow::connections::systemBus = systemBus.get();
55
56 auto server = sdbusplus::asio::object_server(systemBus);
57
58 std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
59 server.add_interface("/xyz/openbmc_project/bmcweb",
60 "xyz.openbmc_project.bmcweb");
61
62 iface->register_method("SetLogLevel", setLogLevel);
63
64 iface->initialize();
Ed Tanous3cd70722024-04-06 09:24:01 -070065
66 // Static assets need to be initialized before Authorization, because auth
67 // needs to build the whitelist from the static routes
68
Ed Tanous25b54db2024-04-17 15:40:31 -070069 if constexpr (BMCWEB_STATIC_HOSTING)
70 {
71 crow::webassets::requestRoutes(app);
72 }
Ed Tanous3cd70722024-04-06 09:24:01 -070073
Ed Tanous25b54db2024-04-17 15:40:31 -070074 if constexpr (BMCWEB_KVM)
75 {
76 crow::obmc_kvm::requestRoutes(app);
77 }
Ed Tanous3cd70722024-04-06 09:24:01 -070078
Ed Tanous25b54db2024-04-17 15:40:31 -070079 if constexpr (BMCWEB_REDFISH)
80 {
81 redfish::RedfishService redfish(app);
Ed Tanous3cd70722024-04-06 09:24:01 -070082
Ed Tanous25b54db2024-04-17 15:40:31 -070083 // Create EventServiceManager instance and initialize Config
84 redfish::EventServiceManager::getInstance(&*io);
Ed Tanous3cd70722024-04-06 09:24:01 -070085
Ed Tanous25b54db2024-04-17 15:40:31 -070086 if constexpr (BMCWEB_REDFISH_AGGREGATION)
87 {
88 // Create RedfishAggregator instance and initialize Config
89 redfish::RedfishAggregator::getInstance(&*io);
90 }
91 }
Ed Tanous3cd70722024-04-06 09:24:01 -070092
Ed Tanous25b54db2024-04-17 15:40:31 -070093 if constexpr (BMCWEB_REST)
94 {
95 crow::dbus_monitor::requestRoutes(app);
96 crow::image_upload::requestRoutes(app);
97 crow::openbmc_mapper::requestRoutes(app);
98 }
Ed Tanous3cd70722024-04-06 09:24:01 -070099
Ed Tanous25b54db2024-04-17 15:40:31 -0700100 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
101 {
102 crow::obmc_console::requestRoutes(app);
103 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700104
Ed Tanous3cd70722024-04-06 09:24:01 -0700105 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700106
Ed Tanous25b54db2024-04-17 15:40:31 -0700107 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
108 {
109 crow::ibm_mc::requestRoutes(app);
110 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700111
Ed Tanous25b54db2024-04-17 15:40:31 -0700112 if constexpr (BMCWEB_GOOGLE_API)
113 {
114 crow::google_api::requestRoutes(app);
115 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700116
Ed Tanous3cd70722024-04-06 09:24:01 -0700117 crow::login_routes::requestRoutes(app);
118
Jayaprakash Mutyalaff0a0882024-06-26 09:08:53 +0000119 if constexpr (!BMCWEB_REDFISH_DBUS_LOG)
Ed Tanous3cd70722024-04-06 09:24:01 -0700120 {
Ed Tanous2185dde2024-11-22 11:33:51 -0800121 int rc = redfish::startEventLogMonitor(*io);
Ed Tanous25b54db2024-04-17 15:40:31 -0700122 if (rc != 0)
123 {
124 BMCWEB_LOG_ERROR("Redfish event handler setup failed...");
125 return rc;
126 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700127 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700128
Ed Tanous25b54db2024-04-17 15:40:31 -0700129 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700130 {
131 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
132 crow::hostname_monitor::registerHostnameSignal();
133 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700134
135 bmcweb::registerUserRemovedSignal();
136
137 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700138
139 systemBus->request_name("xyz.openbmc_project.bmcweb");
140
Ed Tanous3cd70722024-04-06 09:24:01 -0700141 io->run();
142
143 crow::connections::systemBus = nullptr;
144
Ed Tanous9ed3f902024-07-15 17:54:31 -0700145 // TODO(ed) Make event log monitor an RAII object instead of global vars
Ed Tanous2185dde2024-11-22 11:33:51 -0800146 redfish::stopEventLogMonitor();
Ed Tanous9ed3f902024-07-15 17:54:31 -0700147
Ed Tanous3cd70722024-04-06 09:24:01 -0700148 return 0;
149}