blob: b03786027f5b539b8f9bc91430d2330c4bf02de0 [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
Ed Tanous41fe81c2024-09-02 15:08:41 -070028#include <algorithm>
Ed Tanous5b904292024-04-16 11:10:17 -070029#include <memory>
Ed Tanous41fe81c2024-09-02 15:08:41 -070030#include <string>
31#include <string_view>
Ed Tanous3cd70722024-04-06 09:24:01 -070032
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070033static void setLogLevel(const std::string& logLevel)
34{
35 const std::basic_string_view<char>* iter =
36 std::ranges::find(crow::mapLogLevelFromName, logLevel);
37 if (iter == crow::mapLogLevelFromName.end())
38 {
39 BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
40 return;
41 }
42 crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
43 BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
44}
45
Ed Tanous3cd70722024-04-06 09:24:01 -070046int run()
47{
48 auto io = std::make_shared<boost::asio::io_context>();
49 App app(io);
50
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070051 std::shared_ptr<sdbusplus::asio::connection> systemBus =
52 std::make_shared<sdbusplus::asio::connection>(*io);
53 crow::connections::systemBus = systemBus.get();
54
55 auto server = sdbusplus::asio::object_server(systemBus);
56
57 std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
58 server.add_interface("/xyz/openbmc_project/bmcweb",
59 "xyz.openbmc_project.bmcweb");
60
61 iface->register_method("SetLogLevel", setLogLevel);
62
63 iface->initialize();
Ed Tanous3cd70722024-04-06 09:24:01 -070064
65 // Static assets need to be initialized before Authorization, because auth
66 // needs to build the whitelist from the static routes
67
Ed Tanous25b54db2024-04-17 15:40:31 -070068 if constexpr (BMCWEB_STATIC_HOSTING)
69 {
70 crow::webassets::requestRoutes(app);
71 }
Ed Tanous3cd70722024-04-06 09:24:01 -070072
Ed Tanous25b54db2024-04-17 15:40:31 -070073 if constexpr (BMCWEB_KVM)
74 {
75 crow::obmc_kvm::requestRoutes(app);
76 }
Ed Tanous3cd70722024-04-06 09:24:01 -070077
Ed Tanous25b54db2024-04-17 15:40:31 -070078 if constexpr (BMCWEB_REDFISH)
79 {
80 redfish::RedfishService redfish(app);
Ed Tanous3cd70722024-04-06 09:24:01 -070081
Ed Tanous25b54db2024-04-17 15:40:31 -070082 // Create EventServiceManager instance and initialize Config
83 redfish::EventServiceManager::getInstance(&*io);
Ed Tanous3cd70722024-04-06 09:24:01 -070084
Ed Tanous25b54db2024-04-17 15:40:31 -070085 if constexpr (BMCWEB_REDFISH_AGGREGATION)
86 {
87 // Create RedfishAggregator instance and initialize Config
88 redfish::RedfishAggregator::getInstance(&*io);
89 }
90 }
Ed Tanous3cd70722024-04-06 09:24:01 -070091
Ed Tanous25b54db2024-04-17 15:40:31 -070092 if constexpr (BMCWEB_REST)
93 {
94 crow::dbus_monitor::requestRoutes(app);
95 crow::image_upload::requestRoutes(app);
96 crow::openbmc_mapper::requestRoutes(app);
97 }
Ed Tanous3cd70722024-04-06 09:24:01 -070098
Ed Tanous25b54db2024-04-17 15:40:31 -070099 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
100 {
101 crow::obmc_console::requestRoutes(app);
102 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700103
Ed Tanous3cd70722024-04-06 09:24:01 -0700104 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700105
Ed Tanous25b54db2024-04-17 15:40:31 -0700106 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
107 {
108 crow::ibm_mc::requestRoutes(app);
109 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700110
Ed Tanous25b54db2024-04-17 15:40:31 -0700111 if constexpr (BMCWEB_GOOGLE_API)
112 {
113 crow::google_api::requestRoutes(app);
114 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700115
Ed Tanous3cd70722024-04-06 09:24:01 -0700116 crow::login_routes::requestRoutes(app);
117
Jayaprakash Mutyalaff0a0882024-06-26 09:08:53 +0000118 if constexpr (!BMCWEB_REDFISH_DBUS_LOG)
Ed Tanous3cd70722024-04-06 09:24:01 -0700119 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700120 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
121 if (rc != 0)
122 {
123 BMCWEB_LOG_ERROR("Redfish event handler setup failed...");
124 return rc;
125 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700126 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700127
Ed Tanous25b54db2024-04-17 15:40:31 -0700128 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700129 {
130 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
131 crow::hostname_monitor::registerHostnameSignal();
132 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700133
134 bmcweb::registerUserRemovedSignal();
135
136 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700137
138 systemBus->request_name("xyz.openbmc_project.bmcweb");
139
Ed Tanous3cd70722024-04-06 09:24:01 -0700140 io->run();
141
142 crow::connections::systemBus = nullptr;
143
Ed Tanous9ed3f902024-07-15 17:54:31 -0700144 // TODO(ed) Make event log monitor an RAII object instead of global vars
145 redfish::EventServiceManager::stopEventLogMonitor();
146
Ed Tanous3cd70722024-04-06 09:24:01 -0700147 return 0;
148}